본문 바로가기

기존카테고리/JAVA

상속

 

 

class Employee {
String name;
int age;

// public Employee() {
// this("강호동", 49);
// }

public Employee(String name, int age) {
this.name = name;
this.age = age;
}

public void getInfo() {
System.out.println("이름: "+name+" \n나이: "+age);
}
}

class Waiter extends Employee {
String dress;

public Waiter(String name, int age, String dress) {
super(name, age);
this.dress = dress;
}

public void getInfo() {
System.out.println("이름: "+name+" \n나이: "+age+" \n옷차림: "+dress);
}
}

public class Restaurant {

public static void main(String[] args) {
Waiter waiter = new Waiter("김태희", 38, "투피스");
waiter.getInfo();
}

}

'기존카테고리 > JAVA' 카테고리의 다른 글

GenericDemo  (0) 2017.06.28
객체직렬화(Serializable) 사용방법 & 이유(펌)  (0) 2017.06.26