package ch04;
public class Banana extends Fruit{
String origin;
public Banana() {
super.name = "바나나";
super.price = 2000;
origin = "필리핀";
}
}
package ch04;
public class Peach extends Fruit {
public Peach() {
super.name = "복숭아";
super.price = 3900;
} //이 클래스는 peach로 볼수도 있고 상속관계인 fruit이라는 클래스로도 볼수있다 = 다형성
}
package ch04;
public class Fruit {
String name;
int price;
public void showInfo() {
System.out.println("=======");
System.out.println("상품명 : " + name);
System.out.println("가격 : " + price);
System.out.println("=======");
}
}
'Java > Excercise' 카테고리의 다른 글
abstract ch01 Animal (0) | 2021.08.30 |
---|---|
inheritance ch04 FruitTest (0) | 2021.08.27 |
inheritance ch03 Person Student Teacher (0) | 2021.08.27 |
inheritance ch02 Hero (0) | 2021.08.27 |
inheritance ch01 상속 02 (0) | 2021.08.27 |