August 2004
Intermediate to advanced
480 pages
9h 41m
English
The second type of inner class is the method local inner class (MLIC). The name sez it all. We're talking about a class defined inside of a method body.
The primary difference between a regular inner class and an mlic is that the MLIC cannot use the local variables of the method that contains the inner class definition. Only in the event that local variables or arguments are declared final can an object of an inner class access them.
package net.javagarage.inner; /**<p> * Demos Method Local Inner Class * </p> **/ public class OuterMethodLocal { public final int x = 5; public int outY = 10; //the method int someMethod() { final int inX = 5; int inY = 10; class InnerClass { //do some wicked ...Read now
Unlock full access