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

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

練習(xí)題這么做可以吧???反正是運(yùn)行出來(lái)了

父類Vehicle代碼:

package com.imooc;

public class Vehicle {
?? ?public String way;
?? ?public int num;
?? ?public String name;
?? ?public static void getWay(){
?? ??? ?System.out.println("各交通工具的運(yùn)輸路徑分別是:");
?? ?}
?? ?public static void getNum(){
?? ??? ?System.out.println("各交通工具的承載人數(shù)分別是:");
?? ?}
}

子類car代碼:

package com.imooc;

public class Car extends Vehicle {
?? ?public int num=20;
}

測(cè)試類Initailv代碼:
package com.imooc;

public class Initailv {
?? ?public static void main(String[] args) {
?? ??? ?// TODO Auto-generated method stub
?? ??? ?Vehicle car=new Vehicle();
?? ??? ?car.name="汽車";
?? ??? ?car.way="陸地";
?? ??? ?car.num=20;
?? ??? ?Vehicle ship=new Vehicle();
?? ??? ?ship.name="輪船";
?? ??? ?ship.way="海洋";
?? ??? ?ship.num=200;
?? ??? ?Vehicle plane=new Vehicle();
?? ??? ?plane.name="飛機(jī)";
?? ??? ?plane.way="空中";
?? ??? ?plane.num=500;
?? ??? ?Vehicle.getWay();
?? ??? ?System.out.println(car.name+":"+car.way);
?? ??? ?System.out.println(ship.name+":"+ship.way);
?? ??? ?System.out.println(plane.name+":"+plane.way);
?? ??? ?Vehicle.getNum();
?? ??? ?System.out.println(car.name+":"+car.num);
?? ??? ?System.out.println(ship.name+":"+ship.num);
?? ??? ?System.out.println(plane.name+":"+plane.num);
?? ?}
}


正在回答

4 回答

可以了,但是不夠簡(jiǎn)潔,后面學(xué)習(xí)到封裝,繼承和多態(tài)會(huì)更加簡(jiǎn)潔的,代碼的維護(hù)度更強(qiáng)

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

暖風(fēng)align 提問(wèn)者

非常感謝!
2016-01-25 回復(fù) 有任何疑惑可以回復(fù)我~

沒(méi)有用到封裝

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

倒數(shù)第六行和倒數(shù)第十行,調(diào)用方法要用對(duì)象。你用的是類。

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

寫(xiě)的太復(fù)雜了,但是是正確的

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

舉報(bào)

0/150
提交
取消

練習(xí)題這么做可以吧???反正是運(yùn)行出來(lái)了

我要回答 關(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)