public class Test {
public static void main(String[] args) {
Vehicle obj1=new Bus("公交车","陆地上",40);
Vehicle obj2=new Bus("轮船","海上",200);
Vehicle obj3=new Bus("飞机","空中",100);
obj1.info();
obj2.info();
obj3.info();
}
}
public class Bus extends Vehicle {
private String name;
public Bus() {}
public Bus(String name,String space,int person) {
this.setName(name);
super.setSpace(space);
super.setPerson(person);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;}
public void info() {
System.out.println(this.getName()+"在"+super.getSpace()+",载客"+super.getPerson()+"人。");
}
}
public class Ship extends Vehicle {
private String name;
public Ship() {}
public Ship(String name,String space,int person) {
this.setName(name);
super.setSpace(space);
super.setPerson(person);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void info() {
System.out.println(this.getName()+"在"+super.getSpace()+",载客"+super.getPerson()+"人。");
}
}
public class Plane extends Vehicle {
private String name;
public Plane() {}
public Plane(String name,String space,int person) {
this.setName(name);
super.setSpace(space);
super.setPerson(person);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void info() {
System.out.println(this.getName()+"在"+super.getSpace()+",载客"+super.getPerson()+"人。");
}
}
你想要表达什么。。