Skip to content

Commit

Permalink
[Week2][Chap9] super - 생성자 (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
arinming committed Jan 16, 2024
1 parent f7039ea commit 4efb7a4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions 김아린/java-basic/src/extends1/super2/ClassA.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package extends1.super2;

public class ClassA {

public ClassA() {
System.out.println("ClassA 생성자");
}
}
13 changes: 13 additions & 0 deletions 김아린/java-basic/src/extends1/super2/ClassB.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
8 changes: 8 additions & 0 deletions 김아린/java-basic/src/extends1/super2/ClassC.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package extends1.super2;

public class ClassC extends ClassB {
public ClassC() {
super(10, 20); // 부모에게 기본 생성자가 있으므로 생략 불가
System.out.println("ClassC 생성자");
}
}
9 changes: 9 additions & 0 deletions 김아린/java-basic/src/extends1/super2/Super2Main.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 4efb7a4

Please sign in to comment.