From 4efb7a4ff68434b6ebde581a27dfcf23bc641946 Mon Sep 17 00:00:00 2001 From: arinming Date: Tue, 16 Jan 2024 22:19:46 +0900 Subject: [PATCH] =?UTF-8?q?[Week2][Chap9]=20super=20-=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=20(#15)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java-basic/src/extends1/super2/ClassA.java" | 8 ++++++++ .../java-basic/src/extends1/super2/ClassB.java" | 13 +++++++++++++ .../java-basic/src/extends1/super2/ClassC.java" | 8 ++++++++ .../java-basic/src/extends1/super2/Super2Main.java" | 9 +++++++++ 4 files changed, 38 insertions(+) create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/extends1/super2/ClassA.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/extends1/super2/ClassB.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/extends1/super2/ClassC.java" create mode 100644 "\352\271\200\354\225\204\353\246\260/java-basic/src/extends1/super2/Super2Main.java" diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/extends1/super2/ClassA.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/extends1/super2/ClassA.java" new file mode 100644 index 0000000..df45103 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/extends1/super2/ClassA.java" @@ -0,0 +1,8 @@ +package extends1.super2; + +public class ClassA { + + public ClassA() { + System.out.println("ClassA 생성자"); + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/extends1/super2/ClassB.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/extends1/super2/ClassB.java" new file mode 100644 index 0000000..ac8305b --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/extends1/super2/ClassB.java" @@ -0,0 +1,13 @@ +package extends1.super2; + +public class ClassB extends ClassA { + public ClassB(int a) { + this(a, 0); // 매개 변수가 없는 기본 생성자는 생략 가능 + System.out.println("ClassB 생성자 a = " + a); + } + + public ClassB(int a, int b) { + super(); // 생략 가 + System.out.println("ClassB 생성자 a = " + a + " b = " + b); + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/extends1/super2/ClassC.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/extends1/super2/ClassC.java" new file mode 100644 index 0000000..8f22a11 --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/extends1/super2/ClassC.java" @@ -0,0 +1,8 @@ +package extends1.super2; + +public class ClassC extends ClassB { + public ClassC() { + super(10, 20); // 부모에게 기본 생성자가 있으므로 생략 불가 + System.out.println("ClassC 생성자"); + } +} diff --git "a/\352\271\200\354\225\204\353\246\260/java-basic/src/extends1/super2/Super2Main.java" "b/\352\271\200\354\225\204\353\246\260/java-basic/src/extends1/super2/Super2Main.java" new file mode 100644 index 0000000..8d69b7a --- /dev/null +++ "b/\352\271\200\354\225\204\353\246\260/java-basic/src/extends1/super2/Super2Main.java" @@ -0,0 +1,9 @@ +package extends1.super2; + +public class Super2Main { + public static void main(String[] args) { +// ClassC classC = new ClassC(); + + ClassB classB = new ClassB(100); + } +}