A local inner class
is (usually) associated with an instance of the outer class. See this example:
<code><pre>public class Outer {
public void show() {
System.out.println("show() in Outer");
}
public void method() {
System.out.println("method() in Outer");
class Local {
public void show() {
System.out.println("show() in Local");
}
public void method() {
System.out.println("\nmethod() in Local");
System.out.println("\ncalling this.show()");
this.show();
System.out.println("\ncalling Outer.this.show()");
Outer.this.show(); }
}
Local local = new Local();
local.method();
}
public static void main(
String[] args) {
new Outer().method();
}
}</pre></code>
The line "Outer.this.show()" is possible because an inner class does have a reference to an instance of the outer enclosing class, which can be accessed using "
[classname].this". The only time this isn't true is if the local class in defined inside a static context.
Sankar, your statements are true, but that's not what the Jaworski question actually said. The
word "associated" is kind of vague in this case but I'm sure that if you can access an instance of the outer class, then that means an instance is somehow "associated" with the local class instance, and that means Jaworski's statement is FALSE.