This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I studied the static inner class and concluded these. Anyone please correct me if I am wrong. 1. when modifier "static" applying to a class, it can only be applied to a class nested in another class. 2. a static inner class can contain non-static varibles and methods. 3. To access the static methods in a static class, use the class name or class instance, to access the non-static methods in a static class, use class instance. Thanks
Inner classes may inherit static members that are not compile-time constants even though they may not declare them. Nested classes that are not inner classes may declare static members freely, in accordance with the usual rules of the Java programming language. Member interfaces (�8.5) are always implicitly static so they are never considered to be inner classes.
So that's right, too.
3. To access the static methods in a static class, use the class name or class instance, to access the non-static methods in a static class, use class instance.
That's how it is for all static methods and instance methods, regardless of whether or not that class is nested.
One other note - a member class that is given the attribute static is not considered an inner class. Rather, it is called a top-level nested class. A true inner class must have an instance of the enclosing class associated with it - a top-level nested class does not. I hope that helps, Corey