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

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
 
I've been selected to go to the moon! All thanks to this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic