public class ChildExample {
public static void main(String[] args) {
Child child = new Child();
}
}
public class Parent {
public String nation;
public Parent() {
this("대한민국"); // 얘를 불러줄 아래 메서드가 필요함
System.out.println("Parent() call");
}
// 오버로드 되어있음
public Parent(String nation) {
// super(); 이지만 object
this.nation = nation;
System.out.println("Parent(String nation) call");
}
}
public class Child extends Parent {
public String name;
// 1번 호출
public Child() {
this("홍길동"); // 이걸 처리하기 위해 밑의 메서드로
System.out.println("Child() call");
}
public Child(String name) {
// super();가 생략되어 있음 Parent로 넘어감
this.name = name;
System.out.println("Child(String name) call");
}
}
실행 결과