You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
482 B

public class VehicleTest {
public static void main(String[] args) {
// 1. 创建Vehicle数组,存放不同子类对象
Vehicle[] vehicles = {
new Car(),
new Bike(),
new Truck()
};
// 2. 遍历数组,调用每个对象的run()方法
System.out.println("\n=== 进阶题抽象类多态测试 ===");
for (Vehicle v : vehicles) {
v.run();
}
}
}