老师留的作业,帮忙看下对吗
父类:
package com.imooc03;
public class Traffictools {
public String way;
public int num;
public void way() {
// TODO Auto-generated method stub
String way1="Bus";
String way2="Ship";
String way3="Plane";
System.out.println("陆地运输方式采用的运输工具是:"+way1);
System.out.println("海洋运输方式采用的运输工具:"+way2);
System.out.println("空中采用的运输工具是:"+way3);
}
public void num() {
// TODO Auto-generated method stub
int num1=40;
int num2=200;
int num3=500;
System.out.println("Bus的承载人数是: " + num1);
System.out.println("Ship的承载人数是: " + num2);
System.out.println("Plane的承载人数是: " + num3);
}
}
子类:
package com.imooc03;
public class Bus extends Traffictools {
public String way1="Car";
@Override
public void way() {
// TODO Auto-generated method stub
super.way();
System.out.println("陆地运输方式采用的运输工具是:"+way1);
}
}
测试类:
package com.imooc03;
public class Test {
public static void main(String[] args) {
Traffictools obj1=new Traffictools();
Bus obj2=new Bus();
obj1.way();
obj1.num();
obj2.way();
}
}