課程
/后端開發(fā)
/Java
/Java入門第二季 升級(jí)版
是不是做錯(cuò)了 感覺不對(duì)呢 大佬指點(diǎn)一下
2019-07-09
源自:Java入門第二季 升級(jí)版 9-7
正在回答
可以用構(gòu)造方法創(chuàng)建對(duì)象的時(shí)候往里面寫數(shù)據(jù),另外,父類的屬性子類可以直接用 this. 就行了
public Bus(Int people,String way){
this.people = people;
this.way = way;
}
//創(chuàng)建對(duì)象,和構(gòu)造方法對(duì)應(yīng)
Vehicle obj1 = new Bus(40,"公交");
obj1.Vway();
王大哈哈i 提問者
唯進(jìn)
慕容0262671
public?class?HelloWorld?{????public?int?people;????public?String?way;????public?void?Abc(){????????????System.out.println("交通工具為:"+way+"\n乘車人數(shù):"+people?????????????);????????????}???public?class?bus?extends?HelloWorld{????public???bus(int?people,String?way){ ???this.people=people;???????this.way=way;??????this.Abc();????}???}public?class?run?extends?HelloWorld{????public???run(int?people,String?way){ ???this.people=people;???????this.way=way;???????this.Abc();????}???} public?static?void?main(String[]?args)?{???????? ? HelloWorld?num=new?HelloWorld(); bus?nums=num.new?bus(40,"公交");????????run?numss=nums.new?run(4,"跑步"); ???? }}
public class HelloWorld {
? ? public int people;
? ? public String way;
? ? public void Abc(){
? ? ? ?
? ? ?System.out.println("交通工具為:"+way+"\n乘車人數(shù):"+people? ? ? ? ? ? ?);
? ? ? ??
? ? }
? ?public class bus extends HelloWorld{
? ? public? ?bus(int people,String way){
? ?this.people=people;
? ? ? ?this.way=way;
? ? ? this.Abc();
? ?}
public class run extends HelloWorld{
? ? public? ?run(int people,String way){
? ? ? ?this.Abc();
public static void main(String[] args) {
?
HelloWorld num=new HelloWorld();
bus nums=num.new bus(40,"公交");
? ? ? ? run numss=nums.new run(4,"跑步");
? ??
舉報(bào)
課程升級(jí)!以終為始告別枯燥,在開發(fā)和重構(gòu)中體會(huì)Java面向?qū)ο缶幊痰膴W妙
3 回答是不是做錯(cuò)了 感覺不對(duì)呢 大佬指點(diǎn)一下
6 回答大佬們進(jìn)來指點(diǎn)一下。謝謝了
1 回答大佬們指教一下
3 回答總會(huì)感覺不對(duì)
1 回答請(qǐng)大家?guī)兔纯?,指點(diǎn)一下,感謝!
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2019-07-09
可以用構(gòu)造方法創(chuàng)建對(duì)象的時(shí)候往里面寫數(shù)據(jù),另外,父類的屬性子類可以直接用 this. 就行了
public Bus(Int people,String way){
this.people = people;
this.way = way;
}
//創(chuàng)建對(duì)象,和構(gòu)造方法對(duì)應(yīng)
Vehicle obj1 = new Bus(40,"公交");
obj1.Vway();
2020-04-29
2020-04-29
public class HelloWorld {
? ? public int people;
? ? public String way;
? ? public void Abc(){
? ? ? ?
? ? ?System.out.println("交通工具為:"+way+"\n乘車人數(shù):"+people? ? ? ? ? ? ?);
? ? ? ??
? ? }
? ?public class bus extends HelloWorld{
? ? public? ?bus(int people,String way){
? ?this.people=people;
? ? ? ?this.way=way;
? ? ? this.Abc();
? ? }
? ?}
public class run extends HelloWorld{
? ? public? ?run(int people,String way){
? ?this.people=people;
? ? ? ?this.way=way;
? ? ? ?this.Abc();
? ? }
? ?}
public static void main(String[] args) {
? ? ? ??
?
HelloWorld num=new HelloWorld();
bus nums=num.new bus(40,"公交");
? ? ? ? run numss=nums.new run(4,"跑步");
? ??
}
}