One small doubt. We can create an instance of the outer class from the inner class right.
From Sandra reply , quoted below.
"In your Summary, the second point should say,'local class in a static method cannot access outer class instance variables,since there is no this reference. So only static class variables
and final method variables."
We can access the instance variables of enclosing class through its instance.
Look at the code below.
public class Outer {
private int x = 5;
static int y = 6;
public static void main(String args[]) {
System.out.println("in main");
Outer.method();
System.out.println("end of main");
}
static void method() {
class inner {
inner() {
System.out.println(new Outer().x);
}
}
new inner();
}
}
Produces the output
in main
5
end of main
Any comments.
Thanks
Deepa