Java Reference
In-Depth Information
Chapter 5. Nested Classes and Interfaces
Every nonzero finite-dimensional inner product space has an or-
thonormal basis. It makes sense when you don't think about it.
Math Professor, U.C. Berkeley
Classes and interfaces can be declared inside other classes and inter-
faces, either as members or within blocks of code. These nested classes
and nested interfaces can take a number of different forms, each with its
own properties.
The ability to define nested types serves two main purposes. First, nested
classes and nested interfaces allow types to be structured and scoped in-
to logically related groups. Second, and more important, nested classes
can be used to connect logically related objects simply and effectively.
This latter capability is used extensively by event frameworks, such as
the one used in AWT (see " java.awt The Abstract Window Toolkit " on page
717 ) and the JavaBeans component architecture (see " java.beans Com-
ponents " on page 721 ).
A nested type is considered a part of its enclosing type and the two share
a trust relationship in which each can access all members of the other.
Differences between nested types depend on whether the nested type is
a class or an interface, and whether the enclosing type is a class or an
interface. Nested types are either static or not: The former allows simple
structuring of types; the latter defines a special relationship between a
nested object and an object of the enclosing class. Static nested types
are more basic, so we cover them first.
 
Search WWH ::




Custom Search