class 사람
{
공개 문자열 이름;
공용 문자열 주소;
}
class 직원은 Person
{
int 급여를 확장합니다.
public Employee(문자열 이름, 문자열 주소, int salary)
{
this.name=name;
this.address=주소;
this.salary=급여;
}
}
class Director extends Person
{
public Director()
{
this.name= "name";
this.adresse= "주소";
}
}
note:
딸 클래스는 선언된 멤버를 상속합니다
protected 및
public 및
private 상위 클래스와 동일한 패키지에있는 경우.
java의 super 키워드
Person 클래스는 이 회사에 여러 기능이 있다는 점을 고려하여 하위 클래스로 상속되도록 확장 할 수 있습니다. 엔지니어, 회계사, 비서... etc.
class 엔지니어는 Employee
{
public Engineer()
{
super("name","address",110);
}
public void concevoir(){System.out.println("저는 엔지니어입니다");}
공개 무효 developper(){};
}
class 회계사 extends Employee
{
public Accountant()
{
this.name= "name";
this.adresse= "주소";
this.salary = 3000;
}
public void manageAccounts(){};
public void gererLesBilans(){};
}
우리는 계층 구조의 형태로 구조를 볼 수 있으며, 이 트리는 프로그램의 구조를 이해하는 데 도움이 됩니다. Engineer와 Employee의 두 클래스의 차이점은 부모 클래스의 생성자를 직접 호출하는 Engineer에서 super 키워드를 사용한다는 것입니다. 기본적으로,
인수를 사용하여 생성자를 호출합니다.
super 키워드는 상위 클래스의 메서드를 호출하는 데에도 사용됩니다. 예를 들면 다음과 같습니다.