Skip to content

Commit

Permalink
[Week3][Chap10] 다형성과 캐스팅 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjsmk0902 committed Jan 30, 2024
1 parent 1f35ff0 commit a391a77
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions 양승민/java-basic/src/poly/basic/CastingMain1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package poly.basic;

public class CastingMain1 {
public static void main(String[] args) {
//부모 변수가 자식 인스턴스 참조(다형적 참조)
Parent poly = new Child();
//단 자식의 기능은 호출할 수 없다. 컴파일 오류 발생
// poly.childMethod();

//다운캐스팅(부모 타입 -> 자식 타입)
Child child = (Child) poly;
child.childMethod();
}
}

0 comments on commit a391a77

Please sign in to comment.