//创建一个Vehicle类并将它声明为抽象类。
public abstract class Vehicle {
//声明一个名为run的实现打印”Running”功能的方法
public void run() {
System.out.println("Running");
}
//声明一个名为wheelsNum的抽象方法,该方法没有返回值。
public abstract void wheelsNum();
}
public class Motorbike extends Vehicle{
@Override
public void wheelsNum() {
System.out.println("双轮车");
}
}
public class Car extends Vehicle{
@Override
public void wheelsNum() {
System.out.println("四轮车");
}
}
public class Test {
public static void main(String[] args) {
Car car = new Car();
car.run();
car.wheelsNum();
System.out.println("---------------------------");
Motorbike motorbike = new Motorbike();
motorbike.run();
motorbike.wheelsNum();
}
}