Runnable r = new Runnable() { public void run() { System.out.println("This is an anonymous inner class."); } };
ListIn this example, we create a new instance of the ArrayList class using an anonymous inner class. We override the add() method to print a message whenever an element is added to the list. The Class isAnonymousClass is part of the Java Reflection API, which is located in the java.lang.reflect package.list = new ArrayList () { public boolean add(String e) { System.out.println("Adding element: " + e); return super.add(e); } };