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
The inner class can access the outer class methods and properties through its own methods. Look at the following code:
class OuterClass {
String a = "A";
String b = "B";
String c = "C";
class InnerClass{
int x;
public String getA(){
return a; // access the variable a from outer class
}
}
public static class StaticInnerClass{
int x;
}
public String stringConCat(){
return a + b + c;
}
}
public class Test{
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()); // This will print "A"
}
}