Browse Source

w5-张思渊-202401070104

main
zhangsiyuan 2 weeks ago
parent
commit
c8d742d025
  1. 30
      w5/MainVehicle.java

30
w5/MainVehicle.java

@ -0,0 +1,30 @@
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();
}
}
}
Loading…
Cancel
Save