嘘___________别说话
2018-08-01 22:00
public class Test1 {
public static void main(String[] args) {
TransForm[] tra = new TransForm[3];
tra[0] = new Plant("飞机","天空",300);
tra[1] = new Ship("船", "水上", 100);
tra[2] = new Bus("大巴", "路面", 30);
for(TransForm i : tra){
i.print();
}
}
}
/*
* 飞机,轮船,大巴,运输人的数量和方式不同
*/
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+"运输"+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);
}
}
main方法哪去了
test下面
Java入门第二季 升级版
530653 学习 · 6091 问题
相似问题