Java Reference
In-Depth Information
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 Enclosin-
gName . NestedName . The nested type is accessible only if the enclosing type
is accessible.
Static nested types serve as a structuring and scoping mechanism for lo-
gically related types. However, static nested types are members of their
enclosing type and as such can access all other members of the enclos-
ing 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, pack-
age, 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 mod-
ifier 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 ex-
tension 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 ap-
plied to it.
[1] This is a very common structuring idiom.
 
 
Search WWH ::




Custom Search