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


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

in Table To:


© 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