June 2025
Intermediate to advanced
1129 pages
53h
English
Local classes are also inner classes, but these classes aren’t simply set like a property in the body of a class. Instead, you’ll directly define local classes in statement blocks consisting of methods, constructors, and initialization blocks. Local interfaces aren’t possible.
In the following example, the main(...) method declares an inner class named Snowden with a constructor that accesses the final variable PRISM :
public class NSA { public static void main( String[] args ) { final int PRISM = 1; int tempora = 2; tempora++; // (*) class Snowden { Snowden() { System.out.println( PRISM );// System.out.println( tempora ); // Commented out a compiler error } } new Snowden ...
Read now
Unlock full access