源码,没有进行输入限制

来源:10-1 Java 中的多态

嘘___________别说话

2018-08-01 22:00

public class Test1 {

public static void main(String[] args) {

TransForm[] tra = new TransForm[3];

tra[0] = new Plant("飞机","天空",300);

tra[1] = new Ship("船", "水上", 100);

tra[2] = new Bus("大巴", "路面", 30);

for(TransForm i : tra){

i.print();

}

}

}

/*

 * 飞机,轮船,大巴,运输人的数量和方式不同

 */

abstract class TransForm{

protected String name;

protected String ways;

protected int num;

public TransForm(){}

public TransForm (String name,String ways,int num) {

this.name = name;

this.num = num;

this.ways = ways;

}

public void print(){

System.out.println(this.name+"可以在"+this.ways+"运输"+this.num+"人");

}

}

class Plant extends TransForm{

public Plant (String name,String ways,int num) {

super(name,ways,num);

}

}


class Ship extends TransForm{

private String ways = "water";

public Ship(String name,String ways,int num) {

super(name,ways,num);

}

}

class Bus extends TransForm{

public Bus(String name,String ways,int num) {

super(name,ways,num);

}

}


写回答 关注

2回答

  • Passionate1
    2018-08-02 08:14:43
    已采纳

    main方法哪去了

    嘘_____...

    类 Test下面

    2018-08-03 17:57:50

    共 1 条回复 >

  • 嘘___________别说话
    2018-08-03 17:56:08

    https://img.mukewang.com/5b6426a00001bb3702130096.jpgtest下面

Java入门第二季 升级版

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

530653 学习 · 6091 问题

查看课程

相似问题