请看我的作业

来源:10-1 Java 中的多态

KABOKUO

2018-06-22 10:59

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

}

}


写回答 关注

1回答

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

    你想要表达什么。。

Java入门第二季 升级版

课程升级!以终为始告别枯燥,在开发和重构中体会Java面向对象编程的奥妙

530655 学习 · 6091 问题

查看课程

相似问题