• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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: 9708
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...
 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic