Java

๋‹คํ˜•์„ฑPolymorphism

voider 2020. 9. 6. 19:18

๐Ÿ“š ์ž๋ฐ”์˜ ์ •์„์„ ์ •๋ฆฌํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค.

๋‹คํ˜•์„ฑ?

์šด์ „ํ•˜๋Š” ๋ฒ•์€ ํ•œ ๋ฒˆ๋งŒ ๋ฐฐ์šฐ๋ฉด ์–ด๋–ค ์ž๋™์ฐจ๋“  ์šด์ „ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ž๋™์ฐจ ๋ธŒ๋žœ๋“œ๋‚˜ ๋‚ด๋ถ€ ๊ตฌํ˜„์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์ง€์ง€ ์•Š๋Š”๋‹ค. ๋™์ผํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์ด๊ฒŒ ๋‹คํ˜•์„ฑ์ด๋‹ค.

OOP์—์„œ ๋‹คํ˜•์„ฑ์ด๋ž€ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ํ˜•ํƒœ๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š” ๋Šฅ๋ ฅ. ๋งํ•˜์ž๋ฉด ์กฐ์ƒํด๋ž˜์Šค ํƒ€์ž…์˜ ์ฐธ์กฐ๋ณ€์ˆ˜๋กœ ์ž์† ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด๋‹ค.

class Tv {

    boolean power;
    int channel;

    void power{ power = !power;}
    void channelUp() { ++channel;}
    void channelDown() { --channel;}
}

class CaptionTv extends Tv {
    String text;
    void caption() {}
}

CationTv์˜ ์ธ์Šคํ„ด์Šค๋ฅผ Tv caption = new CaptionTv() ์ด๋Ÿฐ ์‹์œผ๋กœ ์ƒ์„ฑํ•  ์ˆ˜๋„ ์žˆ๋‹ค.
๋‹ค๋งŒ ์ด๋Ÿด ๊ฒฝ์šฐ CaptionTv๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” caption()๋Š” ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค.

์ฐธ์กฐ๋ณ€์ˆ˜ ํ˜•๋ณ€ํ™˜

class Car {
    String color;
    int door;

    void drive() {
        System.out.println("drive, brrr....");
    }

    void stop() {
        System.out.println("stop...");
    }
}

class FireEngine extends Car {
    void water() {
        System.out.println("water...");
    }
}
public class CastingTest {
    public static void main(String[] args) {
        Car car = null;
           //FireEngine fire = (FireEngine)new Car(); //ERROR

        FireEngine fireEngine = new FireEngine();
        FireEngine fireEngine2 = new FireEngine();
        fireEngine.water();


        car = fireEngine;
        //car.warter //์‚ฌ์šฉ ๋ถˆ๊ฐ€
        car.stop();
        fireEngine2 = (FireEngine)car;
        fireEngine2.water();
    }
}

ํ˜•๋ณ€ํ™˜์€ ์ฐธ์กฐ๋ณ€์ˆ˜ ํƒ€์ž…์„ ๋ณ€ํ™˜ํ•˜๋Š” ๊ฒƒ์ผ ๋ฟ, ์ธ์Šคํ„ด์Šค๋ฅผ ๋ณ€ํ™˜ํ•˜๋Š” ๊ฒƒ์€ ์•„๋‹ˆ๋‹ค. ์ฐธ์กฐ๋ณ€์ˆ˜๋Š” ๋‹จ์ง€ ์ฐธ์กฐํ•˜๋Š” ์ธ์Šคํ„ด์Šค์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉค๋ฒ„์˜ ๋ฒ”์œ„(๊ฐœ์ˆ˜)๋ฅผ ์กฐ์ ˆํ•œ๋‹ค.

์ž์† -> ์กฐ์ƒ์œผ๋กœ ํ˜•๋ณ€ํ™˜์€ ๊ฐ€๋Šฅํ•˜์ง€๋งŒ
์กฐ์ƒ -> ์ž์†์œผ๋กœ ํ˜•๋ณ€ํ™˜์€ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค.
์™œ?
์‹ค์ œ ์ธ์Šคํ„ด์Šค์ธ Car์˜ ๋ฉค๋ฒ„์˜ ๊ฐœ์ˆ˜๋ณด๋‹ค FireEngine์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉค๋ฒ„ ๊ฐœ์ˆ˜๊ฐ€ ๋” ๋งŽ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

instanceof ์—ฐ์‚ฐ์ž

์ฐธ์กฐ๋ณ€์ˆ˜๊ฐ€ ์ฐธ์กฐํ•˜๊ณ  ์žˆ๋Š” ์ธ์Šคํ„ด์Šค์˜ ์‹ค์ œํƒ€์ž…์„ ์•Œ์•„๋ณผ ๋•Œ ์“ด๋‹ค. booleanํƒ€์ž…์œผ๋กœ returnํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ฃผ๋กœ ์กฐ๊ฑด๋ฌธ์—์„œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.
instanceof์˜ ๊ฒฐ๊ณผ๊ฐ€ true๋ผ๋Š” ๊ฒƒ์€ ์ฐธ์กฐ๋ณ€์ˆ˜๊ฐ€ ๊ฒ€์‚ฌํ•œ ํƒ€์ž…์œผ๋กœ ํ˜•๋ณ€ํ™˜์ด ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ๋œป์ด๋‹ค.

class InstanceofTest{ 
    public static void main(String[] args) {
        MotorCyle motorCycle = new MotorCyle();

        if(motorCycle instanceof MotorCyle) {
            System.out.println("MotorCyle Instance");
        }
        if(motorCycle instanceof Cycle) {
            System.out.println("Cycle Instance");
        }
        if(motorCycle instanceof Object) {
            System.out.println("Object Instance");
        }            
    }
}
class Cycle {}
class MotorCyle extends Cycle{}

/* ๊ฒฐ๊ณผ
MotorCyle Instance
Cycle Instance
Object Instance
*/

MotorCycleํด๋ž˜์Šค๋Š” ์ž๊ธฐ ์ž์‹ ์ธ MotorCycleํƒ€์ž…์ด๋ฉด์„œ, ์กฐ์ƒ์ธ Cycleํƒ€์ž…์ด๋ฉด์„œ, ๊ทธ์˜ ์กฐ์ƒ์ธ Objectํƒ€์ž…์ด๊ธฐ๋„ํ•˜๋‹ค.
์ด์ฒ˜๋Ÿผ instanceof๋Š” ์ž์‹ ์˜ ํƒ€์ž… ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์กฐ์ƒํƒ€์ž…์—๋„ true๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ MotorCycleํƒ€์ž…์€ Cycleํƒ€์ž…์œผ๋กœ๋„, Objectํƒ€์ž…์œผ๋กœ๋„ ํ˜•๋ณ€ํ™˜ ํ•  ์ˆ˜ ์žˆ๋‹ค.

์ฐธ์กฐ๋ณ€์ˆ˜๊ฐ€ ์ฐธ์กฐํ•˜๋Š” ๋ณ€์ˆ˜

๋ฉ”์„œ๋“œ์˜ ๊ฒฝ์šฐ ์กฐ์ƒ ํด๋ž˜์Šค์˜ ๋ฉ”์„œ๋“œ๋ฅผ ์ž์† ํด๋ž˜์Šค์—์„œ ์˜ค๋ฒ„๋ผ์ด๋”ฉ ํ–ˆ๋‹ค๋ฉด, ์ฐธ์กฐ๋ณ€์ˆ˜ ํƒ€์ž…์— ์ƒ๊ด€์—†์ด ์‹ค์ œ ์ธ์Šคํ„ด์Šค์˜ ๋ฉ”์„œ๋“œ(์˜ค๋ฒ„๋ผ์ด๋”ฉํ•œ ๋ฉ”์„œ๋“œ)๊ฐ€ ํ˜ธ์ถœ๋œ๋‹ค.
ํ•˜์ง€๋งŒ ๋ฉค๋ฒผ๋ณ€์ˆ˜์˜ ๊ฒฝ์šฐ ์ด๋ฆ„์ด ๊ฐ™์„ ๊ฒฝ์šฐ ์ฐธ์กฐ ๋ณ€์ˆ˜์— ๋”ฐ๋ผ ๊ฐ’์ด ๋‹ฌ๋ผ์ง„๋‹ค.

class Super {

    int x = 10;
}
class Sub extends {

    int x = 20;

}

class Main {
    public static void main(String[] args) {
        Super s = new Super();
        Sub sub = new Sub();

        System.out.println(s.x); // 10
        System.out.println(sub.x); //20
    }
}

๋งค๊ฐœ๋ณ€์ˆ˜์˜ ๋‹คํ˜•์„ฑ

๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์กฐ์ƒํƒ€์ž…์˜ ์ฐธ์กฐ๋ณ€์ˆ˜๋ฅผ ์„ค์ •ํ•˜๋ฉด, ๋ชจ๋“  ์ž์†ํƒ€์ž…์˜ ์ฐธ์กฐ๋ณ€์ˆ˜๋ฅผ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค.
๋ฐ”๋กœ ์œ„ ์˜ˆ์ œ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ, add(Super x)๋ผ๋Š” ๋ฉ”์„œ๋“œ๊ฐ€ ์žˆ๋‹ค๊ณ  ํ•˜์ž. ๊ทธ๋Ÿผ Super๋ฅผ ์ƒ์†๋ฐ›๋Š” Sub๋„ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค๋Š” ๋œป์ด๋‹ค.

package com.javaex.ch7;
/*
* ๊ฐ€๊ฒฉ๊ณผ ํฌ์ธํŠธ ์ ์ˆ˜๋ฅผ ์ •์˜ํ•ด๋†“์€ ํด๋ž˜์Šค
* ๋ชจ๋“  ์ƒํ’ˆ์ด ๊ฐ€์ง€๊ณ  ์žˆ์–ด์•ผ ํ•  ๊ฒƒ๋“ค์„ ์ •์˜ํ•œ๋‹ค.
* */
class Product {
    int price;
    int bonusPoint;

    /*
    * Product๋ฅผ ์ƒ์†ํ•˜๋Š” ํด๋ž˜์Šค๋“ค์€ ์กฐ์ƒํด๋ž˜์Šค์˜ ์ƒ์„ฑ์žsuper()๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ์ธ์ž๋กœ ๊ฐ€๊ฒฉ์„ ์ž…๋ ฅํ•ด์•ผ ํ•œ๋‹ค.
    * Product()๋Š” ์ž…๋ ฅ๋ฐ›์€ ๊ฐ€๊ฒฉ์œผ๋กœ ๋ณด๋„ˆ์Šคํฌ์ธํŠธ๋ฅผ ์—ฐ์‚ฐํ•ด์„œ ๋ณ€์ˆ˜์— ์ €์žฅํ•œ๋‹ค.
    * */
    Product(int price) {
        this.price = price;
        bonusPoint = (int)(price/10.0); //๊ฐ€๊ฒฉ์˜ 10%๋ฅผ ์ ๋ฆฝํ•œ๋‹ค.
    }
}

class Tv extends Product {
    Tv() { 
        /*์กฐ์ƒํด๋ž˜์Šค์˜ ์ƒ์„ฑ์ž๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ๊ฐ€๊ฒฉ์„ ์ž…๋ ฅ*/
        super(100); //Tv๋Š” 100๋งŒ์›์ด๋‹ค.
    }

    //toString ์˜ค๋ฒ„๋ผ์ด๋”ฉ
    @Override
    public String toString() { return "Tv"; }
}

class Computer extends Product {
    Computer() {super(200);}

    @Override
    public String toString() {return "Computer";}
}

/*
* ๊ตฌ๋งค์ž์˜ ์ •๋ณด๋ฅผ ์ •์˜ํ•œ ํด๋ž˜์Šค
* */
class Buyer {
    int money = 1000;
    int bonusPoint = 0;
    /*
    * ๊ตฌ๋งค์žBuyer๊ฐ€ ์ƒํ’ˆProduct๋ฅผ ๊ตฌ๋งคํ•˜๋ฉด ์ด ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.
    * Product Type์ด๊ธฐ ๋•Œ๋ฌธ์— Product๋ฅผ ์ƒ์†ํ•˜๋Š” ๋ชจ๋“  ํด๋ž˜์Šค๋ฅผ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค.(๋งค๊ฐœ๋ณ€์ˆ˜์˜ ๋‹คํ˜•์„ฑ)
    * ๊ตฌ๋งค์ž๊ฐ€ ๊ฐ€์ง„ ๋ˆ๊ณผ ์ƒํ’ˆ ๊ฐ€๊ฒฉ์„ ๋น„๊ต(์œ ํšจ์„ฑ๊ฒ€์‚ฌ) ํ›„, ๋ˆ์ด ์ถฉ๋ถ„ํ•˜๋‹ค๋ฉด
    * 1.๊ฐ€์ง„ ๋ˆ์—์„œ ์ƒํ’ˆ ๊ฐ€๊ฒฉ์„ ๋บ€๋‹ค.
    * 2.๋ณด๋„ˆ์Šค ์ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•œ ๋‹ค์Œ, ๊ตฌ๋งค์ž์˜ ๋ณด๋„ˆ์ˆ˜์ ์ˆ˜ ๋ณ€์ˆ˜์— ์ €์žฅํ•œ๋‹ค.
    * */
    void buy(Product product) {
        if(money < product.price) {
            System.out.println("์ž”์•ก์ด ๋ถ€์กฑํ•ฉ๋‹ˆ๋‹ค.");
            return;
        }

        money -= product.price;
        bonusPoint += product.bonusPoint;
        System.out.println(product +"์ƒํ’ˆ์„ ๊ตฌ๋งคํ•˜์…จ์Šต๋‹ˆ๋‹ค.");
    }
}

public class PolyArgumentTest {
    public static void main(String[] args) {
        Buyer buyer = new Buyer();

        buyer.buy(new Tv());
        buyer.buy(new Computer());

        System.out.println("๋‚จ์€ ์ž”์•ก "+buyer.money+"๋งŒ์›");
        System.out.println("ํ˜„์žฌ ํฌ์ธํŠธ๋Š” "+buyer.bonusPoint+"์ ");
    }
}

๋‹ค์–‘ํ•œ ํƒ€์ž…์˜ ๊ฐ์ฒด๋ฅผ ๋ฐฐ์—ด๋กœ

๊ฐ™์€ ํด๋ž˜์Šค๋ฅผ ์ƒ์† ๋ฐ›๋Š” ์ž์† ํด๋ž˜์Šค๋“ค์„ ๋ฌถ์–ด์„œ ๊ฐ์ฒด ๋ฐฐ์—ด์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.
๊ทธ๋Ÿฌ๋‹ˆ๊นŒ ์ƒ์† ๋ฐ›๋Š” ํด๋ž˜์Šค๋งŒ ๊ฐ™๋‹ค๋ฉด, ํƒ€์ž…์ด ๋‹ฌ๋ผ๋„ ํ•˜๋‚˜์˜ ๋ฐฐ์—ด๋กœ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ์œ„์˜ ์˜ˆ์ œ๋ฅผ ์•ฝ๊ฐ„ ์ˆ˜์ •ํ•ด์„œ ๋ฐฐ์—ด์„ ๋งŒ๋“ค์—ˆ๋‹ค.

package com.javaex.ch7;

import java.util.Arrays;

/*
* ๊ฐ€๊ฒฉ๊ณผ ํฌ์ธํŠธ ์ ์ˆ˜๋ฅผ ์ •์˜ํ•ด๋†“์€ ํด๋ž˜์Šค
* ๋ชจ๋“  ์ƒํ’ˆ์ด ๊ฐ€์ง€๊ณ  ์žˆ์–ด์•ผ ํ•  ๊ฒƒ๋“ค์„ ์ •์˜ํ•œ๋‹ค.
* */
class Product {
    int price;
    int bonusPoint;

    /*
    * Product๋ฅผ ์ƒ์†ํ•˜๋Š” ํด๋ž˜์Šค๋“ค์€ ์กฐ์ƒํด๋ž˜์Šค์˜ ์ƒ์„ฑ์žsuper()๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ์ธ์ž๋กœ ๊ฐ€๊ฒฉ์„ ์ž…๋ ฅํ•ด์•ผ ํ•œ๋‹ค.
    * Product()๋Š” ์ž…๋ ฅ๋ฐ›์€ ๊ฐ€๊ฒฉ์œผ๋กœ ๋ณด๋„ˆ์Šคํฌ์ธํŠธ๋ฅผ ์—ฐ์‚ฐํ•ด์„œ ๋ณ€์ˆ˜์— ์ €์žฅํ•œ๋‹ค.
    * */
    Product(int price) {
        this.price = price;
        bonusPoint = (int)(price/10.0); //๊ฐ€๊ฒฉ์˜ 10%๋ฅผ ์ ๋ฆฝํ•œ๋‹ค.
    }

    Product() {}
}

class Tv extends Product {
    Tv() { 
        /*์กฐ์ƒํด๋ž˜์Šค์˜ ์ƒ์„ฑ์ž๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ๊ฐ€๊ฒฉ์„ ์ž…๋ ฅ*/
        super(100); //Tv๋Š” 100๋งŒ์›์ด๋‹ค.
    }

    //toString ์˜ค๋ฒ„๋ผ์ด๋”ฉ
    @Override
    public String toString() { return "Tv"; }
}

class Computer extends Product {
    Computer() {super(200);}

    @Override
    public String toString() {return "Computer";}
}

class Audio extends Product {
    Audio() {super(50);}
    @Override
    public String toString() {return "Audio";}
}

/*
* ๊ตฌ๋งค์ž์˜ ์ •๋ณด๋ฅผ ์ •์˜ํ•œ ํด๋ž˜์Šค
* */
class Buyer {
    int money = 1000;
    int bonusPoint = 0;
    //๊ตฌ์ž…ํ•œ ์ œํ’ˆ์„ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•œ ๋ฐฐ์—ด
    Product[] item = new Product[10]; //10๊ฐœ๋ฅผ ๋‹ด์„ ์ˆ˜ ์žˆ๋Š” ์žฅ๋ฐ”๊ตฌ๋‹ˆ
    int i = 0; //๋ฐฐ์—ด์— ์‚ฌ์šฉํ•  index
    /*
    * ๊ตฌ๋งค์žBuyer๊ฐ€ ์ƒํ’ˆProduct๋ฅผ ๊ตฌ๋งคํ•˜๋ฉด ์ด ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.
    * Product Type์ด๊ธฐ ๋•Œ๋ฌธ์— Product๋ฅผ ์ƒ์†ํ•˜๋Š” ๋ชจ๋“  ํด๋ž˜์Šค๋ฅผ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค.(๋งค๊ฐœ๋ณ€์ˆ˜์˜ ๋‹คํ˜•์„ฑ)
    * ๊ตฌ๋งค์ž๊ฐ€ ๊ฐ€์ง„ ๋ˆ๊ณผ ์ƒํ’ˆ ๊ฐ€๊ฒฉ์„ ๋น„๊ต(์œ ํšจ์„ฑ๊ฒ€์‚ฌ) ํ›„, ๋ˆ์ด ์ถฉ๋ถ„ํ•˜๋‹ค๋ฉด
    * 1.๊ฐ€์ง„ ๋ˆ์—์„œ ์ƒํ’ˆ ๊ฐ€๊ฒฉ์„ ๋บ€๋‹ค.
    * 2.๋ณด๋„ˆ์Šค ์ ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•œ ๋‹ค์Œ, ๊ตฌ๋งค์ž์˜ ๋ณด๋„ˆ์ˆ˜์ ์ˆ˜ ๋ณ€์ˆ˜์— ์ €์žฅํ•œ๋‹ค.
    * */
    void buy(Product product) {
        if(money < product.price) {
            System.out.println("์ž”์•ก์ด ๋ถ€์กฑํ•ฉ๋‹ˆ๋‹ค.");
            return;
        }

        money -= product.price;
        bonusPoint += product.bonusPoint;
        item[i++] = product;
        System.out.println(product +"์ƒํ’ˆ์„ ๊ตฌ๋งคํ•˜์…จ์Šต๋‹ˆ๋‹ค.");
    }

    /*๊ตฌ๋งคํ•œ ์ƒํ’ˆ ์ •๋ณด๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ๋ฉ”์„œ๋“œ*/
    void summary() {
        int sum = 0;    //์ด๊ฐ€๊ฒฉ
        String itemList = "";   //์ƒํ’ˆ ๋ชฉ๋ก

        for(int i=0; i<item.length;i++) {
            if(item[i] == null) break;

            sum += item[i].price; //์ƒํ’ˆ ๊ฐ€๊ฒฉ์„ ๋”ํ•œ๋‹ค.
            itemList += item[i] +", ";  //์ƒํ’ˆ๋ช…์„ ์ถ”๊ฐ€ํ•œ๋‹ค.
        }
        System.out.println("๊ตฌ๋งคํ•˜์‹  ์ƒํ’ˆ ๋ชฉ๋ก์€ " +itemList+"์ž…๋‹ˆ๋‹ค.");
        System.out.println("๊ตฌ๋งคํ•˜์‹  ์ƒํ’ˆ ์ด์•ก์€ " +sum+"์ž…๋‹ˆ๋‹ค.");
    }
}

public class PolyArgumentTest {
    public static void main(String[] args) {
        Buyer buyer = new Buyer();

        buyer.buy(new Tv());
        buyer.buy(new Computer());
        buyer.buy(new Audio());

        buyer.summary();

        System.out.println("๋‚จ์€ ์ž”์•ก "+buyer.money+"๋งŒ์›");
        System.out.println("ํ˜„์žฌ ํฌ์ธํŠธ๋Š” "+buyer.bonusPoint+"์ ");

    }
}

'Java' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

๋‚ด๋ถ€ ํด๋ž˜์Šคinner class  (0) 2020.09.09
์ถ”์ƒํด๋ž˜์Šค & ์ธํ„ฐํŽ˜์ด์Šค  (0) 2020.09.09
์ƒ์†Inheritance  (0) 2020.09.06
์ œ์–ด์žModifier  (0) 2020.09.06
๊ฐ์ฒด์ง€ํ–ฅ2  (0) 2020.09.06