I did read a number of topics discussing inner classes, and i was under the impression that an inner class has access to the variables and methods of the enclosing class. In
It seems you're confusing scope and access. References can access only the attributes and methods of the object to which they refer. So your inner.a can't work.
On the other hand, outer class variables are within the scope of methods in a respective inner class. So you can do what you want by defining a read accessor.
public class OuterClass {
String a = "A";
String b = "B";
String c = "C";
class InnerClass{
int x;
String getA() {
return a;
}
}
}
public class TestStatic {
public static void main(String args[]) {
OuterClass.StaticInnerClass staticClass = new OuterClass.StaticInnerClass();
OuterClass outer = new OuterClass();
OuterClass.InnerClass inner = outer.new InnerClass();
System.out.println(inner.getA()); //error should be gone now.
}
}