• 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

INNER CLASS - Is it an error / JLS

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
�8.1.2 Inner Classes and Enclosing Instances
An inner class is a nested class that is not explicitly or implicitly declared static. Inner classes may not declare static initializers or member inter-faces.Inner classes may not declare static members, unless they are compile time constant fields.�
The above statement is taken from Java language Specification(JLS)
What does the above statement actually prove?
As far as I have understood from the above statement, it says that inner class are those class that are not declared as static.
But don�t u have Static Inner Classes as mentioned in Java Certification Guide- Simon Roberts page 186.
This gets confusing!!
Any help on this??
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi jag_nai:
More generally nested classes which are not declared as static are called inner classes where as non static nested classes are the one which are declared inside any class.
hope that clers ur doubt.
geetha.
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at this new message. Are Sun's people confused themselves???
[This message has been edited by Mapraputa Is (edited September 17, 2000).]
 
jag_nai
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Geetha, the problem still persists. Ok, practically when u compile both nested class and the so called inner class works same. And as Michael has himself pointed out, in the question from sun topic, it gets even worse.
Dont u think there should be a clear divide between the two here?
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Static member classes used to be called "top-level nested classes", and were considered top-level, at least according to the original Nested Classes Specification. However this never really caught on, and under the JLS 2nd edition they are no longer considered top-level. I don't think any exam questions ever considered them top-level (or at least, they don't ask about it), so you're safe here.
However, the exam does apparently consider static member classes to be inner classes, even though this is clearly contradicted by the Nested Classes Specification and the JLS2. They don't make a big deal about it - they just call them "static inner classes". So, for the exam, pretend they're inner classes, and remember that in the real world, they aren't.

Here is a summary of types of classes


Hope this helps!
Ajith
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ...
Digging through The Java Programming Language: 2nd Edition by Ken Arnold and James Gosling turns up the following definitions:
Nested classes and interfaces - members of another class or interface. You can declare them to be accessible any way you like.
Static nested class - simplest form of a nested class. Acts just like any top-level class except that it's name and accessiblity are defined by the enclosing class.
A footnote on static nested classes reads:


Static nested classes are formally called "top-level nested classes". Although useful in formal contexts, the term is also oxymoronoic and hence confusing so we do not use it in this book.


non-static nested classes are called inner classes
They go on to state: Inner classes cannot have static members.
Since the following compiles without any errors:

and based on the wording in the text, think, static nested class is probably the clearest term vs 'static inner class' which according to the rules is impossible.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic