title: Method local inner class can access final local variable only.Why?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3910324/why-inner-classes-require-final-outer-instance-variables-java">Why inner classes require “final” outer instance variables [Java]?</a><br>
    <a href="https://stackoverflow.com/questions/4732544/why-are-only-final-variables-accessible-in-anonymous-class">Why are only final variables accessible in anonymous class?</a>  </p>
  </blockquote>
  
  
  
  <pre><code>class Outer{
     private String x = "instance variable";
     void doStuff(){
        String z = "local variable";
        class Inner{
            public void seeOuter(){
            System.out.println("Outer x is : "+ x);  
            System.out.println("Local variable z is : " + z); //won't compile
           }
        } 
    }
  }
  </code></pre>
  
  <p>Marking the local variable z as final fixes the problem :</p>
  
  <pre><code>final String z = "local variable"; //Now inner object can use it.
  </code></pre>
  
  <p><br>
  <strong>Can anyone please explain what is happening ?</strong> <br><br>
  I know exactly why it can not compile in case I am trying to access a non-final local variable.<br><br>
  <strong>Does making a local-variable final allows it to stay alive even if the method gets completed and local variable goes out of scope?<br><br>
  Does final local variables get stored on a heap instead of stack ?</strong></p>