Example of an anonymous innerclass

The interface myInnerInterface

public interface myInnerInterface {   public abstract String myToString(); //you could also call this method "toString()" }

The class myClass

public class myClass {   myClass() {};   public void myClassMethod()   {     System.out.println("hello new class" + new myInnerInterface () {   public String myToString()//this could have implemented toString()   {     return("Hi, What is my name anyway?");   } }.myToString() //if we had implement toString then we could have // entirely removed the call ".myToString()" );//end println   }//end myMethod }

The class myClassTest

public class myClassTest {   public static void main (String args[])   {     myClass a = new myClass();     a.myClassMethod();     return;   } }

© Nachum Danzig January 2004