• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Quession of anonymous inner classes

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is true about anonymous inner classes ?
a)it can implement more than one interfaces
b)it can implement only an interface
c) it can only extend an abstract class
d) it can extend any class
E) it can implement extend a class and implement an interface.
My ANS is b c and you?
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a. wrong since only one interface can be implemented.
b. if the wording was "...only ONE interface" I'd say it's correct.
c. wrong, can extend any class
d. correct
e. if the anonymous class implements an interface it implicitely extends Object, so in this case the answer is true but in the general case it's wrong
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What is true about anonymous inner classes ?


a)it can implement more than one interfaces
False, it can only implement one interface
b)it can implement only an interface
True or False, This one is poorly worded. If they mean that it can only implement an interface and not extend another class then it is false. If they mean that i can only implement interfaces (meaning it cant implement another class) then it is true because only interfaces are implemented, classes are extended. On the other hand, with an annonymous class you dont use either the extends or the implements keyword. I'm leaning towards the False answer, I think they want to klnow if an annonymous class can only be created froman interface not from another class.
c) it can only extend an abstract class
False, it can extend any class that isn't final.
d) it can extend any class
False, it can't extend a final class. Or, true it can extend any class that isn't final.
E) it can implement extend a class and implement an interface.
False, it can do one or the other but not both.
hope that helps


------------------
Dave
Sun Certified Programmer for the Java� 2 Platform
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Hades,
The correct answer is d. Why?
a) False. Anonymous inner classes can't implement more than one interface because it doesn't use the implements approach. It will look something like:
new <interface name> () { <class declarations> };
b) False. The keyword in this sentence is only. An anonymous inner class can implement an interface or extend a non-final class.
c. False. Same reason as above.
d. True. It can extend a non-final class. Since this is the only viable choice we can overlook the missing non-final clause.
e. False. A anonymous inner class can either implement an interface or extend a non-final class. Once again there is no room in the format to perform both at the same time. Extending a class will look like:
new <superclass name> (<optional arg list>) { class declarations };

Regards,
Manfred.
 
Hades Pan
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Valentin Crettaz, Dave Vick,Manfred Leonhardt very very much !! HA HA I think this quession is a game of worded not is a good JAVA PROGRAMMER EXAM
 
CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic