File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Quention on Anonymous Inner Classes

 
Meghna Bhardwaj
Ranch Hand
Posts: 109
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic