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.
30 lines
510 B
30 lines
510 B
abstract class Vehicle{
|
|
public abstract void run();
|
|
}
|
|
class Car extends Vehicle{
|
|
public void run(){
|
|
System.out.println("小轿车驶过");
|
|
}
|
|
}
|
|
class Bike extends Vehicle{
|
|
public void run(){
|
|
System.out.println("自行车驶过");
|
|
}
|
|
}
|
|
class Trunk extends Vehicle{
|
|
public void run(){
|
|
System.out.println("卡车驶过");
|
|
}
|
|
}
|
|
public class MainVehicle{
|
|
public static void main(String[] args){
|
|
Vehicle[] vehicles = {
|
|
new Car(),
|
|
new Bike(),
|
|
new Trunk()
|
|
};
|
|
for(Vehicle v : vehicles){
|
|
v.run();
|
|
}
|
|
}
|
|
}
|