Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

anonymous inner class question required

Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me ammend my answer.

Annonymouse inner classes cannot have constructors of their own.

Using Kathy's code from above (Thanks Kathy)

The inner class at line 7 can not have a constructor. The anonymous class does not have a name. In order to provide a constructor for a class, you need to use the class name.

Hope this clarifies things for you.
Cowgirl and Author
Posts: 1589
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm going to talk about "D"...
Think about anonymous inner class syntax, to figure out if this is correct or not. What are you allowed to say?
Foo f = new Foo() { };

Where Foo can be EITHER a class type, which means that the anonymous class EXTENDS Foo, OR it Foo can be an interface type, where the anonymous class IMPLEMENTS the Foo interface. So how would you say that your anonymous class is BOTH a Foo subtype, and implements some other interface?

As for the constructor arguments one, well, I'm not sure I fully understand the answer the way it is written, but try this code:

And see what you come up with
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
Free, earth friendly heat - from the CodeRanch trailboss
    Bookmark Topic Watch Topic
  • New Topic