-
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.
- Loading branch information
Showing
1 changed file
with
14 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
임준형/java-basic/src/main/java/week3/poly/basic/CastingMain1.java
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 week3.poly.basic; | ||
|
||
public class CastingMain1 { | ||
public static void main(String[] args) { | ||
// 부모 변수가 자식 인스턴스 참조(다형적 참조) | ||
Parent poly = new Child(); // x001 | ||
// 단 자식의 기능은 호출할 수 없다. | ||
// poly.childMethod() // compile error!! | ||
|
||
// 다운 캐스팅(부모 타입 -> 자식 타입) | ||
Child child = (Child) poly; // x001 | ||
child.childMethod(); | ||
} | ||
} |