Skip to content

Commit

Permalink
[Week3][Chap11] 다형성 - 역할과 구현 예제1 (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
toychip committed Feb 13, 2024
1 parent 7f17c14 commit 28f3dbd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 임준형/java-basic/src/main/java/week3/poly/car0/CarMain0.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package week3.poly.car0;

public class CarMain0 {

public static void main(String[] args) {
Driver driver = new Driver();
K3Car k3Car = new K3Car();
driver.setK3Car(k3Car);
driver.drive();

}
}
18 changes: 18 additions & 0 deletions 임준형/java-basic/src/main/java/week3/poly/car0/Driver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package week3.poly.car0;

public class Driver {

private K3Car k3Car;

public void setK3Car(K3Car k3Car) {
this.k3Car = k3Car;
}

public void drive() {
System.out.println("자동차를 운전합니다.");
k3Car.startEngine();
k3Car.pressAccelerator();
k3Car.offEngine();
}

}
16 changes: 16 additions & 0 deletions 임준형/java-basic/src/main/java/week3/poly/car0/K3Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package week3.poly.car0;

public class K3Car {

public void startEngine() {
System.out.println("K3Car.startEngine");
}

public void offEngine() {
System.out.println("K3Car.offEngine");
}

public void pressAccelerator() {
System.out.println("K3Car.pressAccelerator");
}
}

0 comments on commit 28f3dbd

Please sign in to comment.