匿名内部类

//
 package com.egov.builder.nbn;

public interface A {
  public void doSomething();

}
package com.egov.builder.nbn;

public class B {
  
  public void fun(A a){
    System.out.println("fun");
    a.doSomething();
  }

}
package com.egov.builder.nbn;

public class T {

  /**
   * @Methodname: main
   * @Discription: TODO
   * @param args
   * @Return: void
   * @Throws
   *
   */
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    B b = new B();
    b.fun(new A(){

      public void doSomething() {
        System.out.println("匿名内部类");
      }
      
    });
  }

}

你可能感兴趣的:(匿名内部类)