package imooc;
//父类
public class Traffic {
public int nums;
public String ways;
public void show(){
System.out.println(ways + "可以乘坐" + nums + "人");
}
}package imooc;
//子类1
public class Bus extends Traffic{
String ways = "汽车";
int nums = 40;
public Bus(){
}
public void show(){
System.out.println(ways + "\t" + nums);
}
}package imooc;
//子类2
public class Ship extends Traffic{
String ways = "轮船";
int nums = 100;
public Ship(){
}
public void show(){
System.out.println(ways + "\t" + nums);
}
}package imooc;
//子类3
public class Airplane extends Traffic{
String ways = "飞机";
int nums = 200;
public Airplane(){
}
public void show(){
System.out.println(ways + "\t" + nums);
}
}package imooc;
//主函数
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("交通工具\t乘载人数\t");
Traffic bus = new Bus();
bus.show();
Traffic ship = new Ship();
ship.show();
Traffic airplane = new Airplane();
airplane.show();
}
}
添加回答
举报
0/150
提交
取消