• Post Reply Bookmark Topic Watch Topic
  • New Topic

Quession of anonymous inner classes  RSS feed

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • 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?
 
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!