posted 13 years ago
Please consider the below two classes:
I)
Output: Compilation fails
MyOuter2.java:8: local variable z is accessed from within inner class;
needs to be declared final
System.out.println("Local variable z is " + z);
II)
Output: Compiles fine
The only change in the second class is the variable 'z' is marked 'final'
In Kathy Sierra book, it is mentioned that the inner class object cannot use the local variables
of the method the inner class is in.
Even though we make it final, still its a local variable. Please help me to understand how it working when we make it final.