diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car0/CarMain0.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car0/CarMain0.java" index fd7c556..5deb44a 100644 --- "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car0/CarMain0.java" +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car0/CarMain0.java" @@ -8,5 +8,10 @@ public static void main(String[] args) { driver.setK3Car(k3Car); driver.drive(); + // 추가 + Model3Car model3Car = new Model3Car(); + driver.setK3Car(null); + driver.setModel3Car(model3Car); + driver.drive(); } } diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car0/Driver.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car0/Driver.java" index 3a9bff8..281d06f 100644 --- "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car0/Driver.java" +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car0/Driver.java" @@ -3,16 +3,27 @@ public class Driver { private K3Car k3Car; + private Model3Car model3Car; // 추가 public void setK3Car(K3Car k3Car) { this.k3Car = k3Car; } + public void setModel3Car(Model3Car model3Car) { + this.model3Car = model3Car; + } + public void drive() { System.out.println("자동차를 운전합니다."); - k3Car.startEngine(); - k3Car.pressAccelerator(); - k3Car.offEngine(); + if (k3Car != null) { + k3Car.startEngine(); + k3Car.pressAccelerator(); + k3Car.offEngine(); + } else if (model3Car != null) { + model3Car.startEngine(); + model3Car.pressAccelerator(); + model3Car.offEngine(); + } } } diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car0/Model3Car.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car0/Model3Car.java" new file mode 100644 index 0000000..b05e256 --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/car0/Model3Car.java" @@ -0,0 +1,16 @@ +package week3.poly.car0; + +public class Model3Car { + + public void startEngine() { + System.out.println("Model3Car.startEngine"); + } + + public void offEngine() { + System.out.println("Model3Car.offEngine"); + } + + public void pressAccelerator() { + System.out.println("Model3Car.pressAccelerator"); + } +}