-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Week3][Chap12] 다형성 - 역할과 구현 예제1 (#27)
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |