练习的代码,能修改更好吗?是否有冗余或更好的方法。
这个是父类:
package com.imooc;
public class Transportation {
public String name;
public String space;
public int num;
public void getWay(){
}
}
这是其中一个子类:
package com.imooc;
public class Bike extends Transportation {
public String name = "Bike";
public String space = "陆地";
public int num = 2;
public void getWay(){
System.out.println(name+"的运输方式:"+ space+",运输人数:"+num);
}
}
这是main函数:
package com.imooc;
public class Initial {
public static void main(String[] args) {
// TODO Auto-generated method stub
Transportation bike = new Bike();
bike.getWay();
Transportation bus = new Bus();
bus.getWay();
Transportation car = new Car();
car.getWay();
Transportation plane = new Plane();
plane.getWay();
Transportation ship = new Ship();
ship.getWay();
}
}