I'm a beginner struggling with nested classes in general. Here is the first of what will likely amount to several questions on this subject.
In Java, why can't a static nested class be accessed through a reference to an object of the outer class, like other static members.
For example,
class program {
public static void main(String[] args) {
outerClass outerClassRefVar = new outerClass();
int k;
//k = outerClassRefVar.innerClass.i; doesn't compile
k = outerClassRefVar.j; //does compile
}
}
class outerClass {
static class innerClass {
static int i = 1;
}
static int j = 1;
}
...but innerClass and j are both static members of outerClass