This week's book giveaways are in the Jython/Python and Object-Oriented programming forums. We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line! See this thread and this one for details.
The topic is based on a statement made in the tips and tricks section in the following url: http://www.javaranch.com/certfaq.jsp#q11 I thought that static inner classes could have static members. And Also non static inner classes can have final static members. This is confusing. Can someone help?
The JLS does not consider a static inner class to be an inner class, it is a nested class. However: From the JLS 8.1.2
Nested classes that are not inner classes may declare static members freely, in accordance with the usual rules of the Java programming language
And you are technically correct-
An inner class is a nested class that is not explicitly or implicitly declared static. Inner classes may not declare static initializers (�8.7) or member interfaces. Inner classes may not declare static members, unless they are compile-time constant fields (�15.28).
So Inner classes CAN have final static constants declared, but nothing else static.
"JavaRanch, where the deer and the Certified play" - David O'Meara
When I wrote "No inner class can have a static member", I meant those which are not top-level. Though nested classes( top-level static inner classes ) are given the same treatment as inner classes, technically they are different. The JLS 8.1.2 quoted by Cindy makes this point very clear. If the statement in Certification FAQ is confusing, may be we can change the wording....
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).