But in this following code the life time of the main method() exisist through out the inner class ends then it is not compiling.
Yes, but you are assuming that the compiler has special code to detect whether any instances of the inner class escapes the method. Maybe in future versions of
Java, this will be added -- but currently no. So currently, accessing local variables (which are not final) is not allowed.
Henry