composit

김지원·2023년 6월 13일
0

https://inpa.tistory.com/entry/OOP-%F0%9F%92%A0-%EA%B0%9D%EC%B2%B4-%EC%A7%80%ED%96%A5%EC%9D%98-%EC%83%81%EC%86%8D-%EB%AC%B8%EC%A0%9C%EC%A0%90%EA%B3%BC-%ED%95%A9%EC%84%B1Composition-%EC%9D%B4%ED%95%B4%ED%95%98%EA%B8%B0

상속 합성

package ex05.composit;

public class Burger {
    private int price;
    private String desc;

    public Burger() {
        this(1000, "버거");
    }

    public Burger(int price) {
        this(price, "버거");
    }

    public Burger(int price, String desc) {
        this.price = price;
        this.desc = desc;
        System.out.println("버거가 만들어졌습니다");
    }

    public int getPrice() {
        return price;
    }

    public String getDesc() {
        return desc;
    }

}

package ex05.composit;

public class BigBurger extends Burger {

    public BigBurger() {
        super(1500, "빅버거");
        System.out.println("빅버거가 만들어졌습니다");
    }

    public BigBurger(int price, String desc) {
        super(price, desc);
        System.out.println("빅버거가 만들어졌습니다");
    }
}

package ex05.composit;

public class ExApp01 {
    public static void main(String[] args) {
        Burger b1 = new Burger();
        System.out.println("==============");
        Burger b2 = new Burger(800, "버거");
        System.out.println("==============");
        Burger b3 = new Burger(500);
        System.out.println("==============");

        BigBurger bb1 = new BigBurger();
        System.out.println("==============");
        BigBurger bb2 = new BigBurger(1300, "빅버거");
        System.out.println("==============");
    }
}
profile
https://github.com/k7850

0개의 댓글