Basic HTML version of Foils prepared 19 July 97

Foil 21 Inner Classes - Local Classes

From Overview of JDK Version 1.1 Extensions CPS616 -- Information Track of CPS -- Spring Semester 97. by Nancy J. McCracken


A local class is defined within a block a Java code, typically a method, but also static and instance initializers.
The local class is only visible within the block of code in which its defined.
It can use any final (can't be overriden by subclass) local variables or method parameters within its scope.
Syntax: just declare the class and use it entirely within one block, such as a method. (Note that use of "final" modifier is liberalized.)
Unlike member classes, local classes can refer to local variables of block they're defined in.
Typical use of local classes is to define "event listeners".
There are also anonymous local classes, introduced without a name. Special syntax not covered here.



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sun Nov 29 1998