欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java匿名类,

来源: javaer 分享于  点击 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. 要点

  • 匿名类中不能定义静态初始化块
  • 匿名类中不能定义构造方法
  • 匿名类中不能定义接口

 

相关文章

    暂无相关文章
相关栏目:

用户点评