This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Certification Results and the fly likes Quention on Anonymous Inner Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Certification Results
Bookmark "Quention on Anonymous Inner Classes" Watch "Quention on Anonymous Inner Classes" New topic

Quention on Anonymous Inner Classes

Meghna Bhardwaj
Ranch Hand

Joined: Jun 08, 2007
Posts: 109
HI All,

I am preparing for the SCJP 6 and my question is in the below example:
This is from the K&B book, chapter 8, Pg 666, Question 4.

Options are
A. Boo f = new Bar (24) { };
B. Boo f = new Bar() {};
C. Boo f = new Bar() {String s; };
D. Bar f = new Boo(String s) {};
E. Boo f = new Boo.Bar(String s) {};

The correct options are B and C, and until now it all makes good sense to me. But I coded this in eclipse and here is what I tried:

So I am creating a new anonymous inner class and providing a constructor inside it which will accept an integer.
This gives me compiler error. I am wondering why it is possible to only Override the super constructors
and NOT overload them like I am trying.
Any help will be much appreciated. Thanks.

Ankit Garg

Joined: Aug 03, 2008
Posts: 9453

Meghna its not about overloading or overriding constructors. Anonymous inner classes can't declare a constructor whatsoever. So you cannot create a constructor in an Anonymous inner class.

This is a certification results forum. Please Carefully Choose One Forum for your questions...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: Quention on Anonymous Inner Classes
It's not a secret anymore!