Skip to content

Commit

Permalink
[Week3][Chap12] 다형성 - 역할과 구현 예제1 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
arinming committed Feb 6, 2024
1 parent c840abb commit 1ef96c2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 김아린/java-basic/src/poly/car0/CarMain0.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package poly.car0;

public class CarMain0 {
public static void main(String[] args) {
Driver driver = new Driver();
K3Car k3Car = new K3Car();

driver.setK3Car(k3Car);
driver.drive();
}
}
17 changes: 17 additions & 0 deletions 김아린/java-basic/src/poly/car0/Driver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package 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();
}
}
14 changes: 14 additions & 0 deletions 김아린/java-basic/src/poly/car0/K3Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package 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 1ef96c2

Please sign in to comment.