求大神指点更优化的写法
//父类
package traffic;
public class Vehicle {
int Pop ;//运输工具的可载人数
String Move;//运输方式
String Models;//工具类型
public void moveCar(){
System.out.println(Models + "在" + Move +"一次可运输:" + Pop + "人");//创建方法 交通工具可以干什么
}
}
//子类 汽车
package traffic;
public class Car extends Vehicle {
public void moveCar(){
Pop = 5;
Move = "陆地";
Models = "汽车";
System.out.println(Models + "在" + Move +"一次可运输:" + Pop + "人");//创建方法 交通工具可以干什么
}
}
//子类 飞机
package traffic;
public class Aircraft extends Vehicle {
public void moveCar(){
Pop = 50;
Move = "天空";
Models = "飞机";
System.out.println(Models + "在" + Move +"一次可运输:" + Pop + "人");//创建方法 交通工具可以干什么
}
}
//子类飞机
package traffic;
public class Ship extends Vehicle {
public void moveCar(){
Pop = 50;
Move = "海上";
Models = "轮船";
System.out.println(Models + "在" + Move +"一次可运输:" + Pop + "人");//创建方法 交通工具可以干什么
}
}
//演示
package traffic;
public class AppliCation {
public static void main(String[] args) {
// TODO Auto-generated method stub
//Vehicle traFFic = new Vehicle();
Vehicle carModel = new Car();
Vehicle carMode2 = new Aircraft();
Vehicle carMode3 = new Ship();
carModel.moveCar();
carMode2.moveCar();
carMode3.moveCar();
}
}
求大神看看这么写对不对,另外我感觉这种不方便,如果想要随时往里面传参数,应该怎么写?有没有更优化的方法让在下参考下?