File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner classes, K&B book, question doubt. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner classes, K&B book, question doubt." Watch "Inner classes, K&B book, question doubt." New topic
Author

Inner classes, K&B book, question doubt.

Eduardo Mendes
Ranch Hand

Joined: Apr 30, 2008
Posts: 30
Hi,

on page 668 of Kathy and Bert's SCJP5 study guide, I am unclear about the answers provided to question 7 (Answer provided is 'C').

7. Which are true about an anonymous class?
A. It can extend exactly one class and implement exactly one interface
B. It can extend exactly one class and implement multiple interfaces
C. It can extend exactly one class or implement exactly one interface
D. It can implement multiple interfaces regardless of whether it also extends a class
E. It can implement multiple interfaces if it does not extend a class

I would definitely say correct answer is 'C', if the options read "It can DIRECTLY extend..." and/or "It can DIRECTLY implement...".

But, let's say an anonymous class extends class A, and that class A implements multiple interfaces. Than, this anonymous class will implicitly also implement all those interfaces.

So, my doubt is, how to go about this type of questions on the exam? :-(

Thanks!

Best wishes,
Eduardo

[ May 13, 2008: Message edited by: Eduardo Mendes ]

[ May 13, 2008: Message edited by: Eduardo Mendes ]

[ May 13, 2008: Message edited by: Eduardo Mendes ]
[ May 13, 2008: Message edited by: Eduardo Mendes ]
Eduardo Mendes
Ranch Hand

Joined: Apr 30, 2008
Posts: 30
Sorry, but I would really appreciate if someone could help me with this query. My understanding so far is the answer provided to this question is not 100% accurate, and I would like to get some feedback on this.
Joe Fischer
Greenhorn

Joined: May 02, 2008
Posts: 25
When an anonymous class extends another class, it does not matter what the parent class extends or how many interfaces it implements; the anonymous class is still extending exactly one class. Similarly, if the anonymous class "extends" an interface, it is that interface only it is extending regardless of how many other interfaces the parent interface extends.

You might be thinking about IS-A relationships from the anonymous class going up the chain, but that is not what the question asked.


SCJP-SE6.0
Eduardo Mendes
Ranch Hand

Joined: Apr 30, 2008
Posts: 30
Thanks Joe, I got your point. However, maybe I am being a bit pedantic here (or not), but here's an excerpt from the K&B's book, that explains to an extent why I am a bit confused about the question:

Page 652
"The inner class has to choose either to be a subclass of a named class - and not DIRECTLY implement any interfaces at all - or to implement a single interface. By directly we mean actually using the keyword implements as part of the class declaration. If the anonymous inner class is a subclass of a class type, it automatically becomes an implementer of any interfaces implemented by the superclass."

As you see, the expression "directly implement" is used in the Inner classes chapter. From my point of view, this leaves some ground for different interpretations. I was expecting to get some stronger participation to this topic, but I admit the question might not be "sexy" enough for most, so no hard feelings...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner classes, K&B book, question doubt.