클래스나 인터페이스를 구현하는 클래스를 별도로 선언하지 않고, 일회성으로 사용되는 클래스를 익명클래스라고 한다.
public class Example1 {
public static void main(String[] args) throws Exception {
Person age = new Person() {
public void body(){
System.out.print(“body”);
}
};
}
}
interface Person{
void body();
}
class MyThread {
public static void main(String[] arge) {
Thread t = new Thread(new Runnable() {
@override
public void run() {
System.out.println("Child Thread");
}
});
t.start();
System.out.println("Main Thread");
}
}