练习题这么做可以吧???反正是运行出来了
父类Vehicle代码:
package com.imooc;
public class Vehicle {
public String way;
public int num;
public String name;
public static void getWay(){
System.out.println("各交通工具的运输路径分别是:");
}
public static void getNum(){
System.out.println("各交通工具的承载人数分别是:");
}
}
子类car代码:
package com.imooc;
public class Car extends Vehicle {
public int num=20;
}
测试类Initailv代码:
package com.imooc;
public class Initailv {
public static void main(String[] args) {
// TODO Auto-generated method stub
Vehicle car=new Vehicle();
car.name="汽车";
car.way="陆地";
car.num=20;
Vehicle ship=new Vehicle();
ship.name="轮船";
ship.way="海洋";
ship.num=200;
Vehicle plane=new Vehicle();
plane.name="飞机";
plane.way="空中";
plane.num=500;
Vehicle.getWay();
System.out.println(car.name+":"+car.way);
System.out.println(ship.name+":"+ship.way);
System.out.println(plane.name+":"+plane.way);
Vehicle.getNum();
System.out.println(car.name+":"+car.num);
System.out.println(ship.name+":"+ship.num);
System.out.println(plane.name+":"+plane.num);
}
}