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

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

下面程序哪里錯(cuò)呢?(小白一個(gè),別介)

?public class Animal { public int age; public String name; public void eat(){ System.out.println("動(dòng)物具有吃東西的能力"); } public class Dog extends Animal{ } public static void main(String[] args) { Dog dog=new Dog(); dog.age=10; dog.name="xiaotian"; dog.eat(); } }

正在回答

3 回答

你寫的這個(gè)代碼讀起來很不方便。

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

不要將子類定義在父類里面

?public class Animal {

? ? ? ? ?public int age;?

? ? ? ? ?public String name;?

? ? ? ? ?public void eat(){?

? ? ? ? ? ? System.out.println("動(dòng)物具有吃東西的能力");?

? ? ? ?}?

}

public class Dog extends Animal{ }?

public class text{

? ? ? ? ? ? ?public static void main(String[] args)?

? ? ? ? ? ? ?{?

? ? ? ? ? ? ? ? ?Dog dog=new Dog();?

? ? ? ? ? ? ? ? ?dog.age=10; dog.name="xiaotian";?

? ? ? ? ? ? ? ? ?dog.eat();?

? ? ? ? ? ? ?}?

}


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

public void eat(name,age){ System.out.println(name+age+"歲具有吃東西的能力"); }

public static void main(String[] args) { Dog dog=new Dog(); dog.age=10; dog.name="xiaotian"; dog.eat(dog.name,dog.age); } }

或者

import ……Dog;

?public class Animal { public void eat(Dog dog){ System.out.println(dog.name+dog.age+"歲具有吃東西的能力"); } public class Dog extends Animal{ } public static void main(String[] args) { Dog dog=new Dog(); dog.age=10; dog.name="xiaotian"; dog.eat(dog); } }

輸出:xiaotian10歲具有吃東西的能力

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

舉報(bào)

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

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

進(jìn)入課程

下面程序哪里錯(cuò)呢?(小白一個(gè),別介)

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

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

幫助反饋 APP下載

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

公眾號(hào)

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