public class AnonymousInheritanceTest {

  AnonymousInheritanceTest (int x) {
    go(  
       new BaseClassForAnonymous(x) {
         public void print() {
           System.out.println("AnonymousDerivedClass x = " + x);
         }
       } 
       );
  }  

  public void go(BaseClassForAnonymous bc) {
    bc.print();
  }

  public static void main(String[] args) {
    new AnonymousInheritanceTest(5);
  }
}

class BaseClassForAnonymous {

  protected int x;

  public BaseClassForAnonymous(int x) {
    this.x = x;
  }

  public void print() {
    System.out.println("BaseClassForAnonymous x = " + x);
  }
}