Java Reference
In-Depth Information
Note When you compile an enclosing class that contains a static member class,
the compiler creates a classfile for the static member class whose name consists of
For example, compile Listing 3-1 and you will discover EnclosingClass$En-
closedClass.class as well as EnclosingClass.class . This format also
applies to nonstatic member classes.
Nonstatic Member Classes
A nonstatic member class is a non- static member of an enclosing class. Each in-
ing class. The nonstatic member class's instance methods can call instance methods in
theenclosingclassandaccesstheenclosingclassinstance'snonstaticfields. Listing3-5
presents a nonstatic member class declaration.
Listing 3-5. Declaring a nonstatic member class
class EnclosingClass
private int i;
private void m()
class EnclosedClass
void accessEnclosingClass()
i = 1;
Listing3-5 declaresatop-levelclassnamed EnclosingClass withinstancefield
i ,instancemethod m() ,andnonstaticmemberclass EnclosedClass .Furthermore,
EnclosedClass declares instance method accessEnclosingClass() .
Search WWH ::

Custom Search