java匿名类,
分享于 点击 17615 次 点评:243
java匿名类,
1. 匿名子类
class A {...} // 父类 class B extends A{...} // 非匿名子类 class E { public static void main(String args[]) { B b = new B(); A b = new A() { // 匿名子类 ... }; } }
2. 匿名接口
interface Com {...} // 接口 class A implements Com {...} // 接口实现 class E { public static void main(String args[]) { Com com = new A(); Com com = new Com() { // 匿名接口 ... }; } }
3. 要点
- 匿名类中不能定义静态初始化块
- 匿名类中不能定义构造方法
- 匿名类中不能定义接口
相关文章
- 暂无相关文章
用户点评