1 changed files with 30 additions and 0 deletions
@ -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…
Reference in new issue