π ex01
β YalcoChicken.java
public class YalcoChicken {
protected int no;
protected String name;
public YalcoChicken (int no, String name) {
this.no = no;
this.name = name;
}
public void takeHallOrder () {
System.out.printf("%dνΈ %sμ ν μ£Όλ¬Έ λ°μ%n", no, name);
}
}
YalcoChicken
μ λΆλͺ¨λ‘ νλ μμ ν΄λμ€ YalcoChickenDT
λ§λ€κΈ°
extends
μ°μ°μ μ¬μ©β YalcoChickenDT.java
public class YalcoChickenDT extends YalcoChicken {
private boolean driveThruOpen = true;
public YalcoChickenDT(int no, String name) {
super(no, name); // λ€μ μμ μμ λ€λ£° κ²
}
public void setDriveThruOpen(boolean driveThruOpen) {
this.driveThruOpen = driveThruOpen;
}
public void takeDTOrder () {
System.out.printf(
"%dνΈ %sμ λλΌμ΄λΈμ€λ£¨ μ£Όλ¬Έ %s%n",
no, name,
(driveThruOpen ? "λ°μ" : "λΆκ°")
);
}
}
β Main.java
YalcoChickenDT dtStore1 = new YalcoChickenDT(108, "μ² μ");
dtStore1.takeHallOrder();
dtStore1.takeDTOrder();
dtStore1.setDriveThruOpen(false);
dtStore1.takeDTOrder();
dtStore1
μΈμ€ν΄μ€ μ΄ν΄λ³Ό κ²
protected
νλλ€μ private
μΌλ‘ λ°κΏ λ³Ό κ²