prohibit174 2017. 3. 4. 18:01

<내부 클래스>


안쪽에 있는 클래스를 객체 변수처럼 사용하기 위해서 사용

외부 클래스에서 내부 클래스를 사용하려면 안쪽 클래스 객체를 생성하여 호출.


-익명 내부 클래스

클래스 내에서 한번 쓰고 버리는 클래스


class NestedClassExample9 {

    public static void main(String args[]) {

        MessageSender obj = new MessageSender() {

            void send(String message) {

                System.out.println("발신: 마이다스");

                System.out.println("수신: 게이츠");

                System.out.println("메시지: " + message);

                System.out.println();

            }           

        };

        obj.send("굿 모닝");

    }

}