• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

No inner class can have a static Member?

 
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I like tacos! And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic