匿名内部类是没有名称的类,我们将在实例化行直接定义它。
在下面的程序中,我们使用匿名内部类实现nhooo接口的toString()方法,并打印其返回值。
interface nhooo{
public String toString();
}
public class Main implements nhooo {
public static void main(String[] args) {
System.out.print(new nhooo() {
public String toString() {
return "Welcome to Tutorials Point";
}
});
}
}Welcome to Tutorials Point