• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Interfaces

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kathy!!!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic