public class Vehicle {
// 创建五个以上的生活中的交通工具,并同时查看他们运输客人的方式
String name;
String ways;
int peoplenum;
public void getTransport() {
System.out.println("交通工具是:"+name+"; 出行方式是:" +ways +"; 承载人数为:" + peoplenum);
}
}
public class Bus extends Vehicle {
String name = "大巴";
String ways = "陆地";
int peoplenum = 40;
public void getTransport() {
System.out.println("交通工具是:"+name+"; 出行方式是:" +ways +"; 承载人数为:" + peoplenum);
}
}public class Boat extends Vehicle {
String name="游轮";
String ways = "水上";
int peoplenum = 20;
public void getTransport() {
System.out.println("交通工具是:"+name+"; 出行方式是:" +ways +"; 承载人数为:" + peoplenum);
}
}
?public class Plane extends Vehicle {
String name ="飞机";
String ways = "天空";
int peoplenum = 100;
public void getTransport() {
System.out.println("交通工具是:"+name+"; 出行方式是:" +ways +"; 承载人数为:" + peoplenum);
}
}
public class Car extends Vehicle {
String name = "汽车";
String ways = "陆地";
int peoplenum = 4;
public void getTransport() {
System.out.println("交通工具是:"+name+"; 出行方式是:" +ways +"; 承载人数为:" + peoplenum);
}
}
public class Train extends Vehicle {
String name = "火车";
String ways = "陆地";
int peoplenum = 800;
public void getTransport() {
System.out.println("交通工具是:"+name+"; 出行方式是:" +ways +"; 承载人数为:" + peoplenum);
}
}
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Vehicle v1 = new Bus();
Vehicle v2 = new Boat();
Vehicle v3= new Plane();
Vehicle v4 = new Car();
Vehicle v5 = new Train();
v1. getTransport();
v2.getTransport();
v3.getTransport();
v4.getTransport();
v5.getTransport();
}
}运行结果没问 求大神们帮忙看看细节 新手怕细节出错 谢谢大家了
1 回答
已采纳
Simle丶张浩
TA贡献5条经验 获得超0个赞
?public class Plane extends Vehicle { 这里你怎么多了个问号 ; 再有就是父类的 int peoplenum 应该赋初始值=0
添加回答
举报
0/150
提交
取消