package ch02_quiz;
/*
* Person class 를 정의하세요
* - 이름, 나이의 관리가 가능합니다
*
*/
public class Person {
private String name;
private int age;
public Person() {}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {return name;}
public void setName(String name) { this.name=name; }
public int getage() {return age;}
public void setage(int age) { this.age=age; }
void Person_info() {
System.out.println("이름 : " + name);
System.out.println("나이 : " + age + "세");
}
}
--------------------------------------------------------------------------------
//Celebrity
package ch02_quiz;
/*
* Celebrity class 를 정의하고, PersonTest class 에서 테스트 하세요
* - Person class 를 상속받고, 소속사의 관리가 가능합니다
*/
public class Celebrity extends Person {
private String agency;
public Celebrity(String name, int age, String agency) {
super(name, age);
this.agency = agency;
}
public String getAgency() {return agency;}
public void setAgency(String agency) { this.agency=agency; }
public void Celebrity_info() {
System.out.println("----연에인정보----");
super.Person_info();
System.out.println("소속사 : " + agency);
}
}
--------------------------------------------------------------------------------
//Police
package ch02_quiz;
/*
* Police class 를 정의하고, PersonTest class 에서 테스트 하세요
* - Person class 를 상속받고, 계급의 관리가 가능합니다
*/
public class Police extends Person {
private String classes;
public Police(String name, int age, String classes) {
super(name,age);
this.classes = classes;
}
public String getclasses() {return classes;}
public void setclasses(String classes) { this.classes=classes;}
public void Police_info() {
System.out.println("---경찰관 정보---");
super.Person_info();
System.out.println("계급 : " + classes);
}
}
--------------------------------------------------------------------------------
//PersonTest
package ch02_quiz;
public class PersonTest {
public static void main(String[] args) {
Celebrity cb = new Celebrity("홍길동", 24, "하이브");
cb.Celebrity_info();
System.out.println();
Police police = new Police("마동석", 42, "반장");
police.Police_info();
}
}