=====================상속 예제======================
//p219 ~ 220
public class Main {
public static void main(String[] arg){
Salesman2 sales2 = new Salesman2("오정원", "영업부", 100000000,70000000);
System.out.println(sales2.getEmployeeInfo());
}
}
class Employee2 {
String name;
String dept;
int salary;
public Employee2(String name, String dept, int salary) {
this.name = name;
this.dept = dept;
this.salary = salary;
}
String getEmployeeInfo(){
return "이름 : " +name+ ", 부서 : " +dept+", 연봉 : "+salary;
}
}
//다중상속은 java에서 안된다
// Employee2를 상속받은 Salesaman2
class Salesman2 extends Employee2{ //상속
int commisstion;
public Salesman2(String name, String dept, int salary, int commition){
//super() : 부모에게서 상속받은 필드나 메소드를 자식클래스(여기)에서 참조
super(name,dept,salary);
this.commisstion = commition;
}
//
/*
String getEmployeeInfo(){
return "이름 : " +name+ ", 부서 : " +dept+", 연봉 : "+salary
+", 수당 : "+commisstion;
}
*/
//
String getEmployeeInfo(){
return super.getEmployeeInfo() + ", 수당 = " + commisstion;
}
//부모에게서 상속받은 super.getEmployeeInfo() + 자식클래스에서 정의한 수당
}
'연습문제 > JAVA' 카테고리의 다른 글
JAVA - FileExample1번 (0) | 2021.08.13 |
---|---|
Java InterfacePractice2 (인터페이스 예제2 - 0811) (0) | 2021.08.11 |
Java 와 DB 연동-2 내가 참고할 코드 (0806) / github 커맨드 (0) | 2021.08.06 |
Java 와 DB 연동-1 내가 참고할 코드 (0805) (0) | 2021.08.05 |
JAVA 연습문제 6번 7번 (0804) (0) | 2021.08.04 |