• 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

Anonymous Classes

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI all,
One of the questions from Mock exam :
Please select true statement(s) for an anonymous inner class
A) An anonymous class can not extend to a superclass
B) An anonymous class can not implement an interface
C) An anonymous class can extend to a superclass and implement an interface both.
D) An anonymous class can extend to a superclass or implement an interface
According to me the answer to this question should be A,B. But in answers to this mock the right answer is given as D.
HOw can anonymous class extend a class or implement a interface as this type of class dont have class name?
Thanks in advance
Regards,
Harry
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Harry,
You can extend an existing class with an anymous innerclass. Take look at the following code:

for the implementing part, well if you define a new action listener you are just implementing an interface!

If you look at it in that way, D is correct. I don't see any way to do C.
Hope this helps?
Rikko
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An anonymous class either implicity extends a superclass OR implicitly implements an interface. It can not do both.
 
Harry Singh
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rikko,
Can u tell me more about this as i have got the idea but still im not very confident about it. How these extension of anonymous classes an be helpful in programming. Any other uses of anonymous classes apart from adapter classes.
Thanks
Harry
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Harry,
you can read Khalid Mogul's chapter on inner classes. It is free. I do not have website. But you can research it...
Thanks
Barkat
 
Everyone is a villain in someone else's story. Especially this devious tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic