Chapter 09-1  |  중첩클래스와 중첩인터페이스 소개

중첩 클래스

클래스 내부에 선언한 클래스를 말한다.

class ClassName {
	class NestedClassName {
	}
}

중첩 인터페이스

클래스 내부에 선언한 인터페이스를 말한다.

class A {
	[static] interface I {
		void method();
	}
}

확인 문제 ( 09-1 3번 )

package sec01.verify.exma03;

public class Car {
	class Tire { }
	static class Engine { }
}
package sec01.verify.exma03;

public class NestedClassExample {
	public static void main(String[] args) {
		Car myCar = new Car();
		
		Car.Tire tire = myCar.new Tire();
		Car.Engine engine = myCar.new Engine();
	}
} 

Chapter 09-2  |  익명 객체

이름이 없는 객체로 어떤 클래스를 상속하거나, 인터페이스를 구현한 경우에만 만들 수 있다.

부모클래스 변수 = new 부모클래스(){•••};
인터페이스 변수 = new 인터페이스(){•••};