• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Quention on Anonymous Inner Classes

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.




 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic