Nested and Inner Classes

The main driving force for this change in the language was a major change in the way user interface events are handled. In Java 1, user interface events could be delivered only to classes in the user interface hierarchy. As Java applications got larger, this method became slow and inflexible.

Starting with Java 1.1, events can be delivered to any object, but this implies great duplication of code in every class that needs to handle an event. Nested classes are the solution to avoiding this duplication of code and simplifying the process of adding an event handler to a class.

Nested classes have proven to be very useful for providing specialized behavior in many areas of the Java standard library. Although nested classes ...

Get Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.