public class ConTest {
public ConTest() { // 기본 생성자
System.out.println("저는 기본생성자입니다.");
}
public ConTest(String name) {
System.out.println("name이 " + name + "으로 초기화 됨");
}
}
public class Person {
String name;
int age;
String tel;
public Person() {
}
public Person(String name, int age, String tel) {
this.name = name;
this.age = age;
this.tel = tel;
}
}
상속하는 방법
public class Child extends Parent {
// Child 클래스는 Parent 클래스의 자식임을 명시하는 extends 키워드를 사용한다.
}
자식 클래스는 *private 요소를 제외한 부모 클래스의 모든 메서드를 상속받는다.
상속 관계에 있는 부모 클래스에서 이미 정의된 메서드를 자식 클래스에서 재정의하는 것