obvious deficiencies.
C.A.R. Hoare
Chapter 5. Nested Classes and Interfaces
Every nonzero finite-dimensional inner product space has an orthonormal 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 interfaces, 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 into 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 Components" 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.
5.1. Static Nested Types
A nested class or interface that is declared as a static member of its enclosing class or interface acts just
like any non-nested, or top-level, class or interface, except that its name and accessibility are defined by its
enclosing type. The name of a nested type is expressed as EnclosingName.NestedName. The nested
type is accessible only if the enclosing type is accessible.
Static nested types serve as a structuring and scoping mechanism for logically related types. However, static
nested types are members of their enclosing type and as such can access all other members of the enclosing
type including private onesthrough an appropriate object reference of course. This gives the nested type a
special, privileged relationship with the enclosing type.
Because static nested types are members of their enclosing type, the same accessibility rules apply to them as
for other members. For classes this means that a static nested class or interface can have private, package,
protected, or public access, while for interfaces, nested types are implicitly public.
5.1.1. Static Nested Classes
The static nested class is the simplest form of nested class. You declare one by preceding the class declaration
with the static modifier. When nested in an interface, a class declaration is always static and the modifier
is, by convention, omitted. A static nested class acts just like any top-level class. It can extend any other class
(including the class it is a member of),[1] implement any interface and itself be used for further extension by
any class to which it is accessible. It can be declared final or abstract, just as a top-level class can, and
it can have annotations applied to it.