Meaningless Drivel is fun!*
The moose likes Mock Exam Errata and the fly likes JQplus QID:953582884020 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "JQplus QID:953582884020" Watch "JQplus QID:953582884020" New topic
Author

JQplus QID:953582884020

George Dee-Brown
Ranch Hand

Joined: Mar 15, 2001
Posts: 35
JQplus is contradicting Mughal!
Its states the following as being a correct option:
"Anonymous classes cannot be static"
Mughal P243 states "The context determines whether the anomymous class is static" - meaning it can be static if defined in a static context (ie static method).
Any opinions? My money is with Mughal...
regards,
George
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
According to the JLS an anonymous class is never static.

JLS �15.9.5
An anonymous class is always an inner class (�8.1.2); it is never static (�8.1.1, �8.5.2).

They can be declared in a static context however that does not make them static classes.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited July 02, 2001).]


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Chuck Lorenz
Greenhorn

Joined: Jul 06, 2001
Posts: 6
Khalid Mughal posted the following on July 09, 2001 in the Programmers Certification Study forum in response to a similar question.
JLS quote:
"An anonymous class is never abstract (�8.1.1.1). An anonymous class is always an inner class (�8.1.2); it is never static (�8.1.1, �8.5.2). An anonymous class is always implicitly final (�8.1.1.2)."
If you look carefully you will see that the word "static" refers to the keyword in the above quote. I choose to interpret this as meaning that an anonymous class cannot be declared static (<--- keyword).
In our explanation, we are using the word "static" in the non-keyword sense of the word to indicate "an anonymous class declaration in a static context". As the examples presented in this discussion have shown, an anonymous class declared in a static context cannot access instance members in its enclosing context. This is the point we wanted to get across and the fact that such a class is instantiated without any outer object.
We will make sure that such confusion about terminology does not arise in any future edition of the book.
wbw,
khalid mughal
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JQplus QID:953582884020
 
Similar Threads
RHE and inner classes
Passed SCPJ2 with 96%
static keyword
JQ+: I/O QUESTION
Inner Class