第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

不知道哪里錯(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é)");
?? ?}
}
?? ?

正在回答

4 回答

public?class?jicheng?{
????public?static?void?main(String?args[]){
????????rabbit?b1=new?rabbit("兔子");
????????tiger?b2=new?tiger("老虎");
????????//要打印出動(dòng)物名字,需要獲取name
????????System.out.println(b1.name);
????????b1.eat();
????????b1.sleep();
????????System.out.println("");
????????System.out.println(b2.name);
????????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é)");
????}
}


0 回復(fù) 有任何疑惑可以回復(fù)我~

哦哦,對(duì)了額,謝謝啊

0 回復(fù) 有任何疑惑可以回復(fù)我~

輸出的結(jié)果是兔子吃草睡覺(jué),老虎吃肉睡覺(jué),可是運(yùn)行結(jié)果不對(duì),把這個(gè)b1.print();刪除后也還是不行,是怎么回事啊,求大神解答

0 回復(fù) 有任何疑惑可以回復(fù)我~

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)用

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
Java入門第二季 升級(jí)版
  • 參與學(xué)習(xí)       531097    人
  • 解答問(wèn)題       6276    個(gè)

課程升級(jí)!以終為始告別枯燥,在開(kāi)發(fā)和重構(gòu)中體會(huì)Java面向?qū)ο缶幊痰膴W妙

進(jìn)入課程

不知道哪里錯(cuò)了,請(qǐng)大神幫忙指出

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)