不知道哪里錯了,請大神幫忙指出
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("睡覺");
?? ?}
}
class rabbit extends animal{
?? ?public rabbit(String name){
?? ??? ?this.name=name;
?? ?}
?? ?public void eat(){
?? ??? ?System.out.println("吃草");
?? ?}
?? ?public void sleep(){
?? ??? ?System.out.println("睡覺");
?? ?}
}
class tiger extends animal{
?? ?public tiger(String name){
?? ??? ?this.name=name;
?? ?}
?? ?public void eat(){
?? ??? ?System.out.println("吃肉");
?? ?}
?? ?public void sleep(){
?? ??? ?System.out.println("睡覺");
?? ?}
}
?? ?
2016-05-27
2016-05-28
哦哦,對了額,謝謝啊
2016-05-27
輸出的結果是兔子吃草睡覺,老虎吃肉睡覺,可是運行結果不對,把這個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("睡覺");
? ? }
}
class rabbit extends animal{
? ? public rabbit(String name){
? ? ? ? this.name=name;
? ? }
? ? public void eat(){
? ? ? ? System.out.println("吃草");
? ? }
? ? public void sleep(){
? ? ? ? System.out.println("睡覺");
? ? }
}
class tiger extends animal{
? ? public tiger(String name){
? ? ? ? this.name=name;
? ? }
? ? public void eat(){
? ? ? ? System.out.println("吃肉");
? ? }
? ? public void sleep(){
? ? ? ? System.out.println("睡覺");
? ? }
}
?//b1.print();這個方法你沒有定義啊 ,怎么調用