//Vehicle.java
class Vehicle {
public void run() {
System.out.println("차량이 달립니다.");
}
}
//Bus.java
class Bus extends Vehicle {
@Override
public void run() {
System.out.println("버스가 달립니다.");
}
}
//Taxi.java
class Taxi extends Vehicle {
@Override
public void run() {
System.out.println("택시가 달립니다.");
}
}
//Driver.java
class Driver{
public void drive(Vehicle vehicle) {
vehicle.run();
}
}
//DriverTest.java
public class DriverTest {
public static void main(String[] args) {
Driver driver = new Driver();
driver.drive(new Bus()); // 버스가 달립니다.
driver.drive(new Taxi()); // 택시가 달립니다.
}
}