不知道哪里錯(cuò)了,請(qǐng)大神幫忙指出
public class jicheng {
?? ?public static void main(String args[]){
?? ??? ?rabbit b1=new rabbit("兔子");
?? ??? ?tiger b2=new tiger("老虎");
?? ??? ?b1.print();
?? ??? ?b1.eat();
?? ??? ?b1.sleep;
?? ??? ?System.out.println("");
?? ??? ?b2.print();
?? ??? ?b2.eat();
?? ??? ?b2.sleep();
?? ?}
}
class animal{
?? ?protected String name;
?? ?public void eat(){
?? ??? ?System.out.println("吃啊");
?? ?}
?? ?public void sleep(){
?? ??? ?System.out.println("睡覺(jué)");
?? ?}
}
class rabbit extends animal{
?? ?public rabbit(String name){
?? ??? ?this.name=name;
?? ?}
?? ?public void eat(){
?? ??? ?System.out.println("吃草");
?? ?}
?? ?public void sleep(){
?? ??? ?System.out.println("睡覺(jué)");
?? ?}
}
class tiger extends animal{
?? ?public tiger(String name){
?? ??? ?this.name=name;
?? ?}
?? ?public void eat(){
?? ??? ?System.out.println("吃肉");
?? ?}
?? ?public void sleep(){
?? ??? ?System.out.println("睡覺(jué)");
?? ?}
}
?? ?
2016-05-27
2016-05-28
哦哦,對(duì)了額,謝謝啊
2016-05-27
輸出的結(jié)果是兔子吃草睡覺(jué),老虎吃肉睡覺(jué),可是運(yùn)行結(jié)果不對(duì),把這個(gè)b1.print();刪除后也還是不行,是怎么回事啊,求大神解答
2016-05-27
package guqingtong;
public class HelloWorld {
? ? public static void main(String args[]){
? ? ? ? rabbit b1=new rabbit("兔子");
? ? ? ? tiger b2=new tiger("老虎");
? ? ? ? ?
? ? ? ? b1.eat();
? ? ? ? b1.sleep();
? ? ? ? System.out.println("");
? ? ??
? ? ? ? b2.eat();
? ? ? ? b2.sleep();
? ? }
}
class animal{
? ? protected String name;
? ? public void eat(){
? ? ? ? System.out.println("吃啊");
? ? }
? ? public void sleep(){
? ? ? ? System.out.println("睡覺(jué)");
? ? }
}
class rabbit extends animal{
? ? public rabbit(String name){
? ? ? ? this.name=name;
? ? }
? ? public void eat(){
? ? ? ? System.out.println("吃草");
? ? }
? ? public void sleep(){
? ? ? ? System.out.println("睡覺(jué)");
? ? }
}
class tiger extends animal{
? ? public tiger(String name){
? ? ? ? this.name=name;
? ? }
? ? public void eat(){
? ? ? ? System.out.println("吃肉");
? ? }
? ? public void sleep(){
? ? ? ? System.out.println("睡覺(jué)");
? ? }
}
?//b1.print();這個(gè)方法你沒(méi)有定義啊 ,怎么調(diào)用