Java inner classes

Possible duplicates:
You cannot reference a non-final variable inside an inner class defined in another way.
Why do inner classes require “final” external instance variables [Java]?

class MyOuter {    

    private String x = "Outer";
    void doStuff(){
           final String z = "local variable";
           class MyInner {
                 public void seeOuter(){
                        System.out.println("Outer x is" + x);
                        System.out.println("Local variable z is" + z); // does
                        // not compile if final keyword from String z is removed
                 }
           }
     }
}

The above code is working fine. I want to know why the compiler gives an error if I delete the last keyword from String z. What is the difference in the final creation of a keyword?

+5
source share
2 answers

myInner "" scope area , . z. , z , "" , "" .

, , , , z , .

+3

1) z - String, . , (B) z B. B A. , Java . , , , .

0

All Articles