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 Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Interfaces" Watch "Interfaces" New topic
Author

Interfaces

Claudio Roitman
Greenhorn

Joined: Oct 31, 2003
Posts: 18
Hello, I was looking at Java System classes sources and I got some dudes about Interfaces:
Look at the following class declarations:
1)public class LinkedList extends AbstractSequentialList
implements List, Cloneable, java.io.Serializable {...}
2)public abstract class AbstractSequentialList extends AbstractList {...}
and
3)public abstract class AbstractList extends AbstractCollection implements List {}
My question is: Why is it necessary to put "implements List" in LinkedList declaration?
LinkedList is a subclass of AbstractList
( AbstractList --> AbstractSequentialList ---> LinkedList ) AbstractList already declares it implements List interface, so I think LinkedList does not need to declare it explicitly. Am I right?.
BTW , I am taking the SCJP Test in 3 days...I am very nervous!!!
Thanks and sorry about my English!
My question is: Why is it necesary to put "implements List" in LinkedList declaration?
LinkedList is a subclass of AbstractList
( AbstractList --> AbstractSequentialList ---> LinkedList ) AbstractList already declares it implements List interface, so I think LinkedList does not need to declare it explicitly. Am I right?.
BTW , I am taking the SCJP Test in 3 days...I am very nervious!!!
Thanks and sorry about my english!
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Howdy -- you're right... if class A extends class B, then class A automatically IS-A anything that B implements. So A does *not* need to explicitly declare that it implements the things that it IS as a result of being a subclass of B. In other words, yes, if your superclass implements an interface, then you also implement that interface, whether you explicitly say it or not.
So you do not HAVE to say it, but it's a good practice. It makes it explicit in your API that you implement something without the user having to search the inheritance tree to figure out everything that your class implements. Especially good when your class implements things not provided by the inheritance structure, so that when you DO show the interfaces you implement, you list them all, even if some are really coming from other superclasses.
cheers,
Kathy
Claudio Roitman
Greenhorn

Joined: Oct 31, 2003
Posts: 18
Thanks Kathy!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interfaces
 
Similar Threads
Inheritance and implements in abstract class
Multiple implements same interface
Collection
LinkedHashMap extends HashMap implements Map
Cast LinkedList to ArrayList, enjoy the class cast exception