System.out.println(Bigouter.Nested()); //Then why is this not OK ??
You're referring to Nested as if it's a static method whereas a new operator is expected. Wrong syntax.
Joined: Sep 08, 2003
Thanks Vad for your reply But what you have said is exactly my doubt. Why does the compiler complain if we try to access the static innner class just as a static method ?? Why do we need the syntax of new Bigouter.Nested() ?? And as we are using this syntax we are in fact creating an instance of the outer class named Bigouter and then accessing the Nested class. Then how is the statement "Static nested class can be accessed without the instance of the outer class " true ??
Could someone plz. throw light on this ?? i am really confused Thanks,
Please refer to JLS( 8.5), given below . If a member class or interface declared with simple name C is directly enclosed within the declaration of a class with fully qualified name N, then the member class or interface has the fully qualified name N.C.
Joined: Aug 25, 2003
You do not create a new instance of the outer class with this: new Bigouter.Nested(); In fact, an instance of the inner class is created. The inner class in your code is a top-level nested class having no special relationship with the enclosing class other than namespacing resolution. So, the fully qualified name of the inner class is Bigouter.Nested.