public class Fruit {
private String name;
private int price; //private setter getter필요
private String color;
private String from;
public Fruit(){} //생성자
public Fruit(String name, int price, String color, String from) {
this.name = name;
this.price = price;
this.color = color;
this.from = from;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public void info(){
System.out.println("[과일명 :"+name+",가격 :"+price+",색상 :"+color+",원산지 :"+from+"]");
}
// 오버로딩 : 시그니쳐가 다른것을 같은 메소드에 씀
// 오버라이딩 : 부모가 메소드(시그니쳐 까지 같은)를 물려 받은게 마음에 안들어서 일단 물려 받고 내가 바꿈
// 오브젝트에서 toString으로 주소 찍는게 마음에 안듬 => 자식인 Fruit에 다른게 나오도록 바꿈
public String toString(){
return "Fruit {" +
"과일명 : " + name +
", 가격 : " + price +
", 색상 : " + color +
", 원산지 : " + from +
"}";
}
}