1. 상속(Ingeritance)
- 기존 클래스에 기능을 추가하거나 재정의하여 새로운 클래스를 정의하는것
•
각 클래스 간의 포함 관계
// 부모 클래스
class Employee{
String name, address, department;
int age;
int salary;
public Employee(){
}
public Employee(String name, int age, String address, String department){
this.name = name;
this.age = age;
this.address = address;
this.department = department;
}
public void set_salary(int salary){
}
public void printInfo(){
}
public void set_workhours(int time){
}
}
// 자식클래스
// 위의 Employee 클래스를 상속
// 상속 받은 멤버가 default, private 인 경우 접근 x
class Regular extends Employee{
int salary;
public Regular(String name, int age, String address, String department){
super(name, age, address, department);
}
public void set_salary(int salary){
this.salary = salary;
}
public void printInfo(){
System.out.println("이름 : " + super.name);
System.out.println("나이 : " + super.age);
System.out.println("주소 : " + super.address);
System.out.println("부서 : " + super.department);
System.out.println("정규직 \n" + "월급 : " + salary + "\n");
}
}
Java
복사