Previous releases of the Java language required that all classes be declared as members of a package (called top-level classes). The JDK 1.1 release removes this restriction and now allows classes to be declared in any scope (called inner classes).
Among other uses, inner classes provide for a simpler syntax for the creation of adapter classes--classes that implement an interface (or class) required by an API, and delegates the flow of control back to an enclosing "main" object. Using Adapters and Inner Classes to Handle AWT Eventsdiscusses using inner classes for this purpose and provides several examples of it. Or it you want to go straight to code, check out one of these two examples:
MyAdapterclass defined in the
MyTextActionListenerclasses defined the
For details, syntax, restrictions, and so on, refer to the Inner Classes Specification .