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.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

No inner class can have a static Member?

 
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are right.
[This message has been edited by huiying li (edited March 14, 2001).]
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to checkout the following links -
http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#262890

Campfire story - Getting in Touch with your Inner Class
 
Friends help you move. Good friends help you move bodies. This tiny ad will help:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!