From 00c56e77c4aaa4bcc36527f3e78880051905c5ea Mon Sep 17 00:00:00 2001 From: arinming Date: Wed, 31 Jan 2024 23:19:19 +0900 Subject: [PATCH] =?UTF-8?q?[Week3][Chap10]=20=EB=8B=A4=EC=9A=B4=EC=BA=90?= =?UTF-8?q?=EC=8A=A4=ED=8C=85=EA=B3=BC=20=EC=A3=BC=EC=9D=98=EC=A0=90=20(#2?= =?UTF-8?q?7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java-basic/src/poly/basic/CastingMain4.java" | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/poly/basic/CastingMain4.java" 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(); // 실행 불가 + } +}