什么是Java中的匿名内部类?
没有类名声明的内部类称为匿名内部类。
我们同时声明和实例化它们。
通常,它们在需要覆盖类或接口的方法时使用。
示例
abstract class AnonymousInner {
public abstract void myMethod();
}
public class Outer_class {
public static void main(String args[]) {
AnonymousInner inner = new AnonymousInner() {
public void myMethod() {
System.out.println("This is an example of anonymous inner class");
}
};
inner.myMethod();
}
}输出结果
This is an example of anonymous inner class
热门推荐
10 男朋友祝福语简短新年
11 开店送礼祝福语大全简短
12 端午老师祝福语简短优美
13 结婚对白誓言简短祝福语
14 生日祝福语 简短独特高考
15 婆婆生日祝福语短语简短
16 最搞笑生日祝福语简短
17 少先队代表送祝福语简短
18 怎么说祝福语简短