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

各位大神,请问我这样有没有体现多态性?

package com.zp.duotai;


class  Vehicle{

public void Function() {

// System.out.println("交通工具");

}

}

class Airplane extends Vehicle{

String name="飞机";

int number=500;

String way="air";

public void Function() {

System.out.println("交通工具:"+name+",载客人数:"+number+"人,运行方式:"+way);

}

}

class Ship extends Vehicle{

String name="轮船";

int number=200;

String way="water"; 

public void Function() {

System.out.println("交通工具:"+name+",载客人数:"+number+"人,运行方式:"+way);

}

}

class Bus extends Vehicle{

String name="公交车";

int number=40;

String way="road";

public void Function() {

System.out.println("交通工具:"+name+",载客人数:"+number+"人,运行方式:"+way);

}

}


public class jiaotonggongju {


public static void main(String[] args) {

Vehicle air = new Airplane();

Vehicle bus = new Bus();

Vehicle ship = new Ship();

air.Function();

bus.Function();

ship.Function();


}


}

http://img.mukewang.com/5577afd50001270506480191.jpg

提问者:未来的未来_ 2015-06-10 11:32

个回答

  • 慕后端6371887
    2015-07-29 14:47:00

    我把你的代码复制到eclipse运行public class jiaotonggongju这一行也会报错啊

  • Bad__Guy
    2015-06-21 12:57:40

    你这是重写

  • 伊兮尘昔
    2015-06-10 18:23:23

    可以算是