Let's say we have a class Test
like this,
public class Test {
public static void main(String... args) {
}
public static class InnerTest {
public void test() {
}
}
}
I agree that, I should access static fields using the class name, like
Test.main();
Test.InnerTest obj = new Test.InnerTest();
But we can also access the static member's through instances,
Test test = new Test();
test.main(); // Compiler warning but WORKS fine.
// But I can't do any of this.
Test.InnerTest itest = test.new InnerTest(); // Illegal enclosing instance specification for type Test.InnerTest
Test.InnerTest itest = new test.InnerTest(); // test cannot be resolved to a type
Test.InnerTest itest = test.new Test.InnerTest(); // Cannot allocate the member type Test.InnerTest using its compound name when qualified by an enclosing instance. The member type name is resolved relatively to the qualifying instance type
I just want to learn why something like this is not possible? I am not able to completely understand from the errors reported.