class Clothes {
int price;
Clothes(int price){
this.price = price;
}
}
class Shirt extends Clothes{
Shirt(){
super(8000); //조상 생성자 호출
}
}
class Pants extends Clothes{
Pants(){
super(12000);
}
}
class Buyer {
long money = 20000;
--------
void buy(Shirt s){
money = money - s.price;
}
void buy(Pants p){
money = money - p.price;
}
-------- //제품 추가마다 메서드 만들어 줘야함,,비효율..!!
->
void buy(Clothes c){
money = money - c.price;
}
//이런식 다형식 이용
}
Class Test{
public static void main(String[] args) {
Buyer b = new Buyer();
b.buy(new Shirt());
//->Clothes c = new Shirt();
}
}