匿名内部类

(1)匿名内部类

interface A{

       public void fun() ;

}

class X{

       public void fun1(A a){////////接口声明的对象可以调用接口中的方法

              a.fun() ;

       }

       public void fun2(){

              this.fun1(new A(){

                     public void fun(){

                            System.out.println("Hello World!!!") ;

                     }

              }) ;

       }

};

public class NonameDemo02{

       public static void main(String args[]){

              new X().fun2() ;

       }

};

匿名内部类只使用一次。

 

 

 

原文地址:https://www.cnblogs.com/jinzhengquan/p/1941540.html