<< Chapter < Page | Chapter >> Page > |
The screen output The code in Listing 16 produces the screen outputshown in Figure 9
Important considerations The important things to note about the output shown in Listing 16 include:
I encourage you to copy the code from Listing 17 . Compile the code and execute it. Experiment with the code,making changes, and observing the results of your changes. Make certain that you can explain why your changes behave as they do.
In addition to a number of other items, a class definition can contain:
Member classes were explained in the previous module. This module explains local classes. The next module will explain anonymous classes.
A local class is a class that is defined within a block of Java code. While local classes are probably mostfrequently defined within method and constructors, they can also be defined inside static initializer blocks and instance initializers.
An object of the local class must be internally linked to an object of the enclosing class (which I often refer to as the containing object). A local class is truly an inner class because an object of the local class cannot exist in theabsence of an object of the enclosing class.
The methods of a local class have direct access to all the members in the hierarchy of enclosing classes,including private members. In addition, the methods of local classes have access to final local variables and final method parameters in the scope in which the local class is defined.
The containment hierarchy of local classes is independent of the inheritance hierarchy. However, it is technically possible toestablish an inheritance relationship between a local class and one of its enclosing classes.
Local classes may not be declared public , protected , private , or static .
Local classes cannot contain static members.
A local class has approximately the same relationship to a member class that a local variable in a method has to an instance variable of the classcontaining the method.
The next module in this series will explain and discuss anonymous classes, and will also compare anonymous classes to local classes.
This section contains a variety of miscellaneous information.
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?