From cb4af2e42390041cc9a47c791e8806a069179281 Mon Sep 17 00:00:00 2001 From: toychip Date: Mon, 5 Feb 2024 16:19:53 +0900 Subject: [PATCH] =?UTF-8?q?[Week3][Chap10]=20=EB=8B=A4=ED=98=95=EC=84=B1?= =?UTF-8?q?=EA=B3=BC=20=EC=BA=90=EC=8A=A4=ED=8C=85=20(#26)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/week3/poly/basic/CastingMain1.java" | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 "\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/basic/CastingMain1.java" diff --git "a/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/basic/CastingMain1.java" "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/basic/CastingMain1.java" new file mode 100644 index 0000000..6c0ed95 --- /dev/null +++ "b/\354\236\204\354\244\200\355\230\225/java-basic/src/main/java/week3/poly/basic/CastingMain1.java" @@ -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(); + } +}