Inner Local Classes

Inner local classes are perhaps the simplest of the nested classes to write, understand, and use. The following table shows how to create an inner local class. You simply write the declaration of your class in the usual way, and put it inside (local to) a block. The block almost always instantiates an object of the inner class.

Information on the local class is shown in Table 12-3.

Table 12-3. Local class

Java term

Description

Example code

Local class

This is an inner class.

It is local to a block, typically within a method.

void myMethod() {    class MyLocal {         /*code*/         void something() { }    }    MyLocal m = new MyLocal();    foo( m );}

Qualities of an inner local class

A local ...

Get Just Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.