package com.exc;
class TrafficTools{
int num = 1;
String way = "地奔";
public void VWay() {
System.out.println("出行方式是:" + way + " 承载人数为" + num + "人。");
}
}
class Bus extends TrafficTools{
int num = 40;
String way = "公交车";
@Override
public void VWay() {
System.out.println("出行方式是:" + way + " 承载人数为" + num + "人。");
}
}
class Plane extends TrafficTools{
int num = 100;
String way = "飞机";
@Override
public void VWay() {
System.out.println("出行方式是:" + way + " 承载人数为" + num + "人。");
}
}
class Ship extends TrafficTools{
int num = 400;
String way = "轮船";
@Override
public void VWay() {
System.out.println("出行方式是: " + way + " 承载人数为" + num + "人。");
}
}
public class Tests {
public static void main(String[] args) {
TrafficTools tTools = new TrafficTools();
TrafficTools tools1 = new Bus();
TrafficTools tools2 = new Plane();
TrafficTools tools3 = new Ship();
tTools.VWay();
tools1.VWay();
tools2.VWay();
tools3.VWay();
}
}
符合老师讲的多态定义所要求的方法。最直观的方法您运行您所写代码的结果是否与老师所讲一致即可。
父类已经有num和way了,你子类又重新定义了
看不出来您这继承的意义是啥。。。但似乎又能满足练习题的要求。。。
满足老师的要求吗