익명 내부 클래스는 이름이 없는 클래스이며 인스턴스화 라인에서 직접 정의합니다.
예시
다음 프로그램에서는 Anonymous 내부 클래스를 사용하여 TutorialsPoint 인터페이스의 toString() 메서드를 구현하고 반환 값을 출력합니다.
interface TutorialsPoint{
public String toString();
}
public class Main implements TutorialsPoint {
public static void main(String[] args) {
System.out.print(new TutorialsPoint() {
public String toString() {
return "Welcome to Tutorials Point";
}
});
}
} 출력:
Welcome to Tutorials Point