源碼,沒(méi)有進(jìn)行輸入限制
public class Test1 {
public static void main(String[] args) {
TransForm[] tra = new TransForm[3];
tra[0] = new Plant("飛機(jī)","天空",300);
tra[1] = new Ship("船", "水上", 100);
tra[2] = new Bus("大巴", "路面", 30);
for(TransForm i : tra){
i.print();
}
}
}
/*
?* 飛機(jī),輪船,大巴,運(yùn)輸人的數(shù)量和方式不同
?*/
abstract class TransForm{
protected String name;
protected String ways;
protected int num;
public TransForm(){}
public TransForm (String name,String ways,int num) {
this.name = name;
this.num = num;
this.ways = ways;
}
public void print(){
System.out.println(this.name+"可以在"+this.ways+"運(yùn)輸"+this.num+"人");
}
}
class Plant extends TransForm{
public Plant (String name,String ways,int num) {
super(name,ways,num);
}
}
class Ship extends TransForm{
private String ways = "water";
public Ship(String name,String ways,int num) {
super(name,ways,num);
}
}
class Bus extends TransForm{
public Bus(String name,String ways,int num) {
super(name,ways,num);
}
}
2018-08-02
main方法哪去了
2018-08-03