Java Reference
In-Depth Information
to method meth2 within object a1 :
The body of meth2 in a1 can reference z of a1 , method meth of
a0 , variable y of a0 , and static variable x of class Out .
Note that:
meth2 in object a1 can reference variable y of object a0 ;
meth2 of object a3 can reference variable y of object a2 .
Thus, the conventional inside-out rule, together with the fact that each
instance of class Out contains a file drawer for class In , ensures that each method
meth2 references the correct components.
12.4.3
The flattened view of inner classes
Our model of execution has us cramming a file drawer for a class inside the file
drawer for another class. How do we reconcile this model of execution with the
fact that computer memory consists of a sequence of bytes? We can answer this
question partially by providing a flattened view of the classes in which each class
has its own file drawer and no file drawer appears within another. As we discuss
later, this is quite close to how Java implements inner classes.
Recall class Out with its inner class In , as shown in Fig. 12.17, and Fig.
12.18, which shows In 's file drawer inside each instance of Out . Figure 12.19
displays a “flattened” view of the classes in which class In 's drawer is not
crammed within another file drawer.
The first thing to note is that instances of Out do not contain a file drawer
Activity
12-6.4
Out 's file drawer
a0
a2
x ...
Out
Out
y
y
meth()
meth()
In 's file drawer
In 's file drawer
a1
a3
In
In
z
z
meth2()
meth2()
Figure 12.18:
The file drawers for an inner class
Search WWH ::




Custom Search