상속, 다향성 예제
public class Blog {
public static void main(String[] args) {
Employee r = new Regular("강한별", 30, "서울시", "일본취업 5기", 500);
r.printInfo();
System.out.println("-------------------------");
Employee t = new Temporary("약한별", 60, "인천시", "폐지 줍기", 30);
t.printInfo();
}
}
class Employee {
private String name;
private int age;
private String address;
private String department;
private int salary;
Employee(String name, int age, String address, String department) {
this.name = name;
this.age = age;
this.address = address;
this.department = department;
}
void printInfo() {
System.out.println("이름:\t" + name);
System.out.println("나이:\t" + age);
System.out.println("주소:\t" + address);
System.out.println("부서:\t" + department);
}
void setSalary(int salary) {
this.salary = salary;
}
int getSalary() {
return salary;
}
}
class Regular extends Employee {
Regular(String name, int age, String address, String department, int salary) {
super(name, age, address, department);
super.setSalary(salary);
}
void printInfo() {
super.printInfo();
System.out.println("고용형태:\t정규직");
System.out.println("월급:\t" + super.getSalary());
}
}
class Temporary extends Employee {
Temporary(String name, int age, String address, String department, int salary) {
super(name, age, address, department);
super.setSalary(salary);
}
void printInfo() {
super.printInfo();
System.out.println("고용형태:\t비정규직");
System.out.println("월급:\t" + super.getSalary());
}
}
댓글
댓글 쓰기