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

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

老師留的作業(yè),幫忙看下對嗎



父類:

package com.imooc03;


public class Traffictools {

public String way;

public int num;

public void way() {

// TODO Auto-generated method stub

String way1="Bus";

String way2="Ship";

String way3="Plane";


System.out.println("陸地運(yùn)輸方式采用的運(yùn)輸工具是:"+way1);

System.out.println("海洋運(yùn)輸方式采用的運(yùn)輸工具:"+way2);

System.out.println("空中采用的運(yùn)輸工具是:"+way3);

}


public void num() {

// TODO Auto-generated method stub

int num1=40;

int num2=200;

int num3=500;

System.out.println("Bus的承載人數(shù)是: " + num1);

System.out.println("Ship的承載人數(shù)是: " + num2);

System.out.println("Plane的承載人數(shù)是: " + num3);


}


}


子類:

package com.imooc03;


public class Bus extends Traffictools {

public String way1="Car";

@Override

public void way() {

// TODO Auto-generated method stub

super.way();

System.out.println("陸地運(yùn)輸方式采用的運(yùn)輸工具是:"+way1);

}


}

測試類:

package com.imooc03;


public class Test {

public static void main(String[] args) {

Traffictools obj1=new Traffictools();

Bus obj2=new Bus();

obj1.way();

obj1.num();

obj2.way();


}

}


正在回答

10 回答


//交通工具類public?class?Vehicle?{	String?way;//運(yùn)輸方式	int?carry;//承載屬性		//運(yùn)輸方式	public?void?transport(){		System.out.println("通過交通工具運(yùn)輸");	}}
//大巴public?class?Bus?extends?Vehicle?{	String?way?=?"陸地運(yùn)輸";	int?carry?=?40;//?承載人數(shù)	//?運(yùn)輸方式	public?void?transport()?{		System.out.println("大巴:能搭載"+?carry?+"人,"?+?"通過"?+?way);	}}
//飛機(jī)public?class?Plane?extends?Vehicle?{	String?way?=?"空中運(yùn)輸";	int?carry?=?100;//?承載人數(shù)	//?運(yùn)輸方式	public?void?transport()?{		System.out.println("飛機(jī):能搭載"+?carry?+"人,"?+?"通過"?+?way);	}}
//輪船public?class?Ship?extends?Vehicle?{	String?way?=?"海上運(yùn)輸";	int?carry?=?200;//?承載人數(shù)	//?運(yùn)輸方式	public?void?transport()?{		System.out.println("輪船:能搭載"+?carry?+"人,"?+?"通過"?+?way);	}}
//測試類public?class?Test?{	/**	*?@param?args	*/	public?static?void?main(String[]?args)?{		//?TODO?Auto-generated?method?stub		Vehicle?v?=?new?Bus();		Vehicle?v1?=?new?Ship();		Vehicle?v2?=?new?Plane();		v.transport();		v1.transport();		v2.transport();	}}


0 回復(fù) 有任何疑惑可以回復(fù)我~
//父類
public?class?Transport?{
	//num是可載多少人
	public?int?num;
	public?String?vehicleName;
	public?String?way;
	public?Transport(int?num,?String?vehicleName,String?way)?{
		super();
		this.num?=?num;
		this.way=way;
		this.vehicleName?=?vehicleName;
	}

}


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

沒有實(shí)現(xiàn)方法的多態(tài)

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

測試類里實(shí)現(xiàn)多態(tài)要用父類指向子類,Traffictools obj2=new Bus(); 這樣寫。 你的也沒錯(cuò),只是沒有用到多態(tài)

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

//父類

package com.project1;


public class Vehicle {//創(chuàng)建一個(gè)交通工具的類;

//里面定義人數(shù)和車的類型的兩個(gè)屬性和一個(gè)功能的方法;

public int carryNum;

public String models;

public void mode() {

System.out.println("交通工具有運(yùn)輸?shù)墓δ?);

}

public int Num(int newCarryNum) {

carryNum=newCarryNum;

return carryNum;

}

public String Models(String newModels) {

models=newModels;

return models;

}

}

//創(chuàng)建五個(gè)子類,里面重寫了交通工具的功能

package com.project1;


public class Bike extends Vehicle {

public void mode() {

System.out.println("自行車有陸地運(yùn)輸人的功能!");

}


}

package com.project1;


public class Bus extends Vehicle{

public void mode(){

System.out.println("公共汽車有陸地運(yùn)輸人的功能!");

}


}

package com.project1;


public class Car extends Vehicle {

public void mode(){

System.out.println("小轎車有陸地運(yùn)輸人的功能!");

}

}

package com.project1;


public class Plane extends Vehicle {

public void mode() {

System.out.println("飛機(jī)有天上運(yùn)輸人的功能");

}


}

package com.project1;


public class Ship extends Vehicle {

public void mode() {

System.out.println("輪船有水中運(yùn)輸人的功能!");

}


}

//測試了類

package com.project1;


public class Initail {

public static void main(String[] args) {

Vehicle bike=new Bike();

bike.mode();

bike.Num(1);

bike.Models("自行車");

System.out.println("這種交通工具是:"+bike.models+";它能運(yùn)輸:"+bike.carryNum+"人!");

Vehicle bus=new Bus();

bus.mode();

bus.Num(40);

bus.Models("公共汽車");

System.out.println("這種交通工具是:"+bus.models+";它能運(yùn)輸:"+bus.carryNum+"人!");

Vehicle car=new Car();

car.mode();

car.Num(4);

car.Models("小轎車");

System.out.println("這種交通工具是:"+car.models+";它能運(yùn)輸:"+car.carryNum+"人!");

Vehicle ship=new Ship();

ship.mode();

ship.Num(400);

ship.Models("輪船");

System.out.println("這種交通工具是:"+ship.models+";它能運(yùn)輸:"+ship.carryNum+"人!");

Vehicle plane=new Plane();

plane.mode();

plane.Num(200);

plane.Models("飛機(jī)");

System.out.println("這種交通工具是:"+plane.models+";它能運(yùn)輸:"+plane.carryNum+"人!");

}


}


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

我 忘記寫那個(gè) 交通工具的名字了 ? ??

0 回復(fù) 有任何疑惑可以回復(fù)我~
父類
public?class?Transport?{
?String?way;
?int?Persons;
?public?void?transport(){
??System.out.println("運(yùn)輸方式:"+way+",載客量:"+Persons);
?}
}
子類
public?class?Bus?extends?Transport?{
?String?way="陸地";
?int?Persons=40;
?public?void?transport(){
??System.out.println("運(yùn)輸方式:"+way+",載客量:"+Persons);
?}
}
public?class?Ship?extends?Transport?{
?String?way="海洋";
?int?Persons=200;
?public?void?transport(){
??System.out.println("運(yùn)輸方式:"+way+",載客量:"+Persons);
?}
}
public?class?Airplane?extends?Transport?{
?String?way="天空";
?int?Persons=300;
?public?void?transport(){
??System.out.println("運(yùn)輸方式:"+way+",載客量:"+Persons);
?}
}
測試類
public?class?Initail?{
?public?static?void?main(String[]?args)?{
??//?TODO?Auto-generated?method?stub
??Transport?obj1=new?Bus();
??Transport?obj2=new?Ship();
??Transport?obj3=new?Airplane();
??obj1.transport();
??obj2.transport();
??obj3.transport();
?}
}


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

qq_褻瀆_3

請問這個(gè)使用super是不是更方便一些 為什么我使用super不報(bào)錯(cuò)但是不出結(jié)果
2017-11-02 回復(fù) 有任何疑惑可以回復(fù)我~

感覺你這個(gè)? 是不是? 有點(diǎn)麻煩?


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

沒寫注釋 不知道你哪個(gè)變量代表哪個(gè)意思

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

對的,


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

舉報(bào)

0/150
提交
取消

老師留的作業(yè),幫忙看下對嗎

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

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

幫助反饋 APP下載

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

公眾號(hào)

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