Interfaces Inherited?

If a super class implements an interface does the subclass automatically implement the interface? Obviously the subclass will inherit all the methods required by the interface but would you still need to write the "implements interface" line?

[249 byte] By [Jahvaha] at [2007-11-27 10:41:16]
# 1

No, you do not need to explicitly state again that the class implements that interface. Some people do "for clarity" but really it's less clear to do so - the assumption would be that the superclass did not implement that interface

georgemca at 2007-7-28 19:11:41 > top of Java-index,Java Essentials,New To Java...
# 2

> If a super class implements an interface does the

> subclass automatically implement the interface?

No. The super class already implemented the interface. The sub class use the implementation.

> Obviously the subclass will inherit all the methods

> required by the interface but would you still need to

> write the "implements interface" line?

No

Manuel Leiria

manuel.leiriaa at 2007-7-28 19:11:41 > top of Java-index,Java Essentials,New To Java...
# 3

No, subclasses don't need to declare they implement an interface, which has been declared in a superclass. The subclass will automatically implement the interface, too.

-Puce

Pucea at 2007-7-28 19:11:41 > top of Java-index,Java Essentials,New To Java...
# 4

That makes sense, thanks.

Jahvaha at 2007-7-28 19:11:41 > top of Java-index,Java Essentials,New To Java...
# 5

Remember that implementing an interface and extending a class are just 2 different ways of expressing inheritance, so supertypes are supertypes regardless of whether they're classes or interfaces

georgemca at 2007-7-28 19:11:41 > top of Java-index,Java Essentials,New To Java...