Regarding method local inner class:
In the below code i cannot access "z" from the inner class- it gives a compilation error, due to scope problem...
as "z" is local variable(blows away once the method gets completed) and for the inner class object that will be even the method gets completed(it will resding in the heap.)
class MyOuter2 {
private
String x = "Outer2";
void doStuff() {
String z = "local variable";
class MyInner {
public void seeOuter() {
System.out.println("Outer x is " + x);
System.out.println("Local variable z is " + z); //Won't Compile!
} // close inner class method
} // close inner class definition
} // close outer class method doStuff()
} // close outer class
My question is marking the local variable as final resolves the issue?Please anybody exlpain once what happens when a variable is marked as final... will it be going to reside on heap...!!!