双人鱼L
2017-07-17 17:27
package tra;
public class vehicle {
public String move;
public int num;
public void print(String moveMode,int carryNum){
this.move=moveMode;
this.num=carryNum;
System.out.println("运行方式:"+move+"载客人数:"+num);
}
}
package tra;
public class car extends vehicle {
public void print(){
System.out.println("汽车运输方式:"+move+" 载客人数:"+num);
}
}
package tra;
public class ferry extends vehicle {
public void print(){
System.out.println("轮船运输方式:"+move+" 载客人数:"+num);
}
}
package tra;
public class test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
vehicle b1 = new car();
b1.print("陆行",5);
vehicle b2 = new plan();
b2.print("飞行", 300);
vehicle b3 = new ferry();
b3.print("水航", 500);
}
}
属性赋值的代码可以用构造函数来完成,减少代码量
类名首字母最好大写!
怎么直接写出来啊
你汽车和轮船的print方法里的运输方式可以直接写出来啊为什么还要用move
Java入门第二季 升级版
530652 学习 · 6091 问题
相似问题