问答详情
源自:10-1 Java 中的多态

请看我的作业

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()+"人。");

}

}


提问者:KABOKUO 2018-06-22 10:59

个回答

  • 听说过晚风么
    2018-06-22 21:59:13

    你想要表达什么。。