課程
/后端開發
/Java
/Java入門第二季 升級版
。。。。。
2019-07-20
源自:Java入門第二季 升級版 10-1
正在回答
package tran;
public class Bus extends trano{
/**
* @param args
*/
{? ?mode="陸地行走";
name="汽車";
number= 25;
}
? ? public void were(){
? ? System.out.println(name+"具有"+mode+"的能力,它一次能載"+number+"人");
? ? }
public class fly extends trano{
{? ?mode="天空飛行";
name="飛機";
number= 50;
}? ?
public void were(){
public class boat extends trano{
{? ?mode="海上航行";
name="輪船";
number= 400;
public class trano {
? ? ?public String mode;
? ? ?public String name;
? ? ?public int number;
? ? ?public void were(){
? ? ? System.out.println(name+"具有"+mode+"的能力,它一次能載"+number+"人");
? ? ?}
public class Initail {
public static void main(String[] args) {
// TODO Auto-generated method stub
? ? ? ?trano a = new Bus();
? ? ? ?trano b = new fly();
? ? ? ?trano c = new boat();
? ? ? ?a.were();
? ? ? ?b.were();
? ? ? ?c.were();
我是萌新,請多多包涵。
應該是學習多態了吧。這里是使用多態,增強代碼的可維護性。
在Initail1類中,添加一個靜態方法:
public static void? show(Vehicle veh){
????veh.transportaion();
在main()方法中調用:
public static void main(String[] args){
????show(new Bus());
????show(new Plane());
????show(new Ship())
我也是新手,會有不足之處,共同努力吧。
慕娘6592639
weixin_慕的地9048726 提問者
舉報
課程升級!以終為始告別枯燥,在開發和重構中體會Java面向對象編程的奧妙
4 回答大佬們看看我寫的行嗎
1 回答大佬們看看這個問題
4 回答大佬們,這樣的話有問題嗎?
1 回答這里第三行和第六行應該怎么改才好?
4 回答這句什么意思 看不懂= = 求大佬們解答
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2019-07-31
package tran;
public class Bus extends trano{
/**
* @param args
*/
{? ?mode="陸地行走";
name="汽車";
number= 25;
}
? ? public void were(){
? ? System.out.println(name+"具有"+mode+"的能力,它一次能載"+number+"人");
? ? }
}
package tran;
public class fly extends trano{
/**
* @param args
*/
{? ?mode="天空飛行";
name="飛機";
number= 50;
}? ?
public void were(){
? ? System.out.println(name+"具有"+mode+"的能力,它一次能載"+number+"人");
? ? }
}
package tran;
public class boat extends trano{
/**
* @param args
*/
{? ?mode="海上航行";
name="輪船";
number= 400;
}? ?
public void were(){
? ? System.out.println(name+"具有"+mode+"的能力,它一次能載"+number+"人");
? ? }
}
package tran;
public class trano {
? ? ?public String mode;
? ? ?public String name;
? ? ?public int number;
? ? ?public void were(){
? ? ? System.out.println(name+"具有"+mode+"的能力,它一次能載"+number+"人");
? ? ?}
}
package tran;
public class Initail {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
? ? ? ?trano a = new Bus();
? ? ? ?trano b = new fly();
? ? ? ?trano c = new boat();
? ? ? ?a.were();
? ? ? ?b.were();
? ? ? ?c.were();
}
}
2019-07-26
2019-07-20
應該是學習多態了吧。這里是使用多態,增強代碼的可維護性。
在Initail1類中,添加一個靜態方法:
public static void? show(Vehicle veh){
????veh.transportaion();
}
在main()方法中調用:
public static void main(String[] args){
????show(new Bus());
????show(new Plane());
????show(new Ship())
}
我也是新手,會有不足之處,共同努力吧。