diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/CarMain0.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/CarMain0.java" index 767c3d2..7c5fd53 100644 --- "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/CarMain0.java" +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/CarMain0.java" @@ -7,5 +7,11 @@ 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/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/Driver.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/Driver.java" index e3719c4..ffc5cc0 100644 --- "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/Driver.java" +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/Driver.java" @@ -3,15 +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/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/Model3Car.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/Model3Car.java" new file mode 100644 index 0000000..e1826b6 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/car0/Model3Car.java" @@ -0,0 +1,14 @@ +package 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"); + } +}