Consider the following code:
public final class Test4 {
class Inner {
void
test() {
if (Test4.this.flag); {
sample();
}
}
}
private boolean flag = true;
public void sample() {
System.out.println("Sample");
}
public Test4() {
(new Inner()).test();// line 1
}
public static void main(
String args []) {
new Test4();
}
}
I had assumed it would not compile.The reason is that this inner class's instance should associate with it's enclosing class's instance. So when line 1 runs, there is no instance of enclosing class existing,but an inner class instance is created.
But in fact it can compile without problem.So am I missing something about the relationship between inner class's instance and enclosing class's instance.
Hope to clear me.