Hi there, reading the Java Language Specification in preparation for the SCJP2 exam I came upon a question about nested classes. There is written: 8.1.2 Inner Classes and Enclosing Instances An inner class is a nested class that is not explicitly or implicitly declared static. Can anyone give me an example for a nested class that is implicitly declared static? Thanks in advance Ruediger
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
(Decided the following is NOT true - Cindy) I think this might be when you have a static method that has an inner class, the inner class would be implicitely static in that is would not be associated with an instance of the outer class. This is the example that the JLS gives:
[This message has been edited by Cindy Glass (edited July 26, 2001).]
"JavaRanch, where the deer and the Certified play" - David O'Meara
Ruediger Waurig
Greenhorn
Joined: Jul 24, 2001
Posts: 19
posted
0
Thanks for adding the hint '//this is implicitely Static'. With this answer comes up another question: (JLS means Java Language Specification)
A member class is a class whose declaration is directly enclosed in another class or interface declaration. (JLS 8.5) A local class is a nested class (�8) that is not a member of any class and that has a name. All local classes are inner classes (�8.1.2). Every local class declaration statement is immediately contained by a block. Local class declaration statements may be intermixed freely with other kinds of statements in the block. (JLS 14.3) An inner class is a nested class that is not explicitly or implicitly declared static (JLS 8.1.2) To put it all together: A local class is an inner class. An inner class can't be explicitly or implicitly static. => Is the class 'LocalInStaticContext' a local class and hence can't be implicitly static? Thanks in advance Ruediger
Scott Appleton
Ranch Hand
Joined: May 07, 2001
Posts: 195
posted
0
??? Is my JLS outdated? None of the references given match my 2-volume tome. My JLS 8.5 is Static Initializers and says nothing like the quote given. The same is true for the other quotes.
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
Sorry Scott, I should have given the reference: This if from 8.1.2 Inner Classes and Enclosing Instances http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#262890 It is the second block of sample code given. However, on re-reading this reference I think that it is a poor example, and NOT what they meant (sorry). Actually I believe the original quote about classes that are implicitely static probably refers to nested interfaces (which are .class files)
Member interfaces (�8.5) are always implicitly static so they are never considered to be inner classes.
[This message has been edited by Cindy Glass (edited July 26, 2001).]
Scott Appleton
Ranch Hand
Joined: May 07, 2001
Posts: 195
posted
0
Thanks for the clarification, Cindy. Upon exploring your link I discovered that indeed, my JLS is outdated. I downloaded and printed the pdf all of 2 months ago, but it has since been updated with a new version. Unfortunately, they have altered the references significantly enough that my 850-page document is virtually useless for posting references here. I guess I'm going to have to download the new version and spend another half-day monopolizing the network printer
Ruediger Waurig
Greenhorn
Joined: Jul 24, 2001
Posts: 19
posted
0
Thank you for your investigations, Cindy. I think we've fixed the question very well. Here are some additional quotes on the topic:
9.5 Member Type Declarations Interfaces may contain member type declarations (�8.5). A member type declaration in an interface is implicitly static and public.
8.5 Member Type Declarations A member class is a class whose declaration is directly enclosed in another class or interface declaration. Regards Ruediger