• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • 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
To do a great right, do a little wrong - shakepeare. twisted little ad:
Garden Master Course kickstarter
    Bookmark Topic Watch Topic
  • New Topic