This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Confused about Dan's exam... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Confused about Dan Watch "Confused about Dan New topic

Confused about Dan's exam...

Attila Bak

Joined: Jan 24, 2003
Posts: 5
Suppose we have the following code (from Dan's exam)

Why is class D considered anonymous class in this case?
An anonymous class cannot be static says another explanation in the same exam...
Can you help me on this?
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
In the above code example, the reference to the anonymous class is static; but the anonymous class is not static.
The reference, a1, is static so only one instance of the anonymous class will be created regardless of the number of instances of class C.

Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="" target="_blank" rel="nofollow">Try my mock exam.</a>
Attila Bak

Joined: Jan 24, 2003
Posts: 5
Thanks Dan!
I understand now half of it:-)
Can you enlighten me further why is class D considered an anonymous class?
Thanks in advance!
Sarma Lolla
Ranch Hand

Joined: Oct 21, 2002
Posts: 203

In the above code class D is not anonymous. It is just a static inner class.
The problem is with the anonymous class referred by satic A a1.It can't use implements key word.
Consider Paul's rocket mass heater.
subject: Confused about Dan's exam...