diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/basic/CastingMain4.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/basic/CastingMain4.java" new file mode 100644 index 0000000..f56a10f --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/poly/basic/CastingMain4.java" @@ -0,0 +1,15 @@ +package poly.basic; + +// 다운 캐스팅을 자동으로 하지 않는 이유 +public class CastingMain4 { + public static void main(String[] args) { + Parent parent1 = new Child(); + Child child1 = (Child) parent1; + child1.childMethod(); // 문제 없음 + + Parent parent2 = new Parent(); + + Child child2 = (Child) parent2; // 런타임 오류 - ClassCastException + child2.childMethod(); // 실행 불가 + } +}