Can implementing a interface and extending an class that implements the same interface cause any problems? (other than confusion)
For example:
interface IDo
public abstract class DoIt implements IDo
public class IllDo extends DoIt implements IDo
(please ignore that it just seems wrong)
When you extend a class, you inherit its entire overall interface, including any interfaces it implements or classes it derives from. So any class extending DoIt automatically implements IDo, by the very nature of the fact it's extending a class that implements it. You can put the implements clause on the declaration, but it doesn't have any further effect on the class. There can be reasons to do it, though, as addressed in the answers to this question: It documents that you specifically intend that class to implement the interface, and means that if the superclass is modified to no longer include the implements clause, the subclass either breaks (because it's missing something the interface requires) or keeps its original contract.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With