Title: Should a java class x that extends class y, which implements interface z, also implement interface z
Tags: java;inheritance;polymorphism
Question: I have an interface z. It is implemented by class y. I have another class x that inherits class y. Since y implements the contract specified by class z, x does the same, as it extends class y. Should it therefore also implement interface z?

Here is the accepted answer: No. If the interface is implemented somewhere in the hierarchy of your current class, then that is enough.
In the end, an interface just defines a few methods that a class should contain. To your subclass this is no different than if it were "normal" methods from the top class.
Sample:
public class Main {
public static void main(String[] args) {
new X().test();
new Y().test();
class X extends Y{
class Y implements Z{
@Override
public void test() {
System.out.println("in Y");
interface Z {
public void test();
This will simply output
in Y
in Y
If we change the definition of X to
class X extends Y implements Z
Then the code will still compile without a problem, output stays the same.
If we however implement this method in X then we will hide the method implementation from Y.
Comment for this answer: I don't know if it is an accepted practice but it wouldn't make sense if it is. You can just use the same code (including `@Override` annotation) to override the method from the baseclass.
Comment for this answer: Is this an accepted software practice, or is it that it makes no difference?

Here is another answer: I believe that x.isAssignableFrom(z) will be false unless x explicitly implements z in it's declaration.  (even though the superClass implements z).
Comment for this answer: It is used in reflection to determine if an object will fulfill the interface specified.  Example Account implements Debitable interface (which contains the debit() method).  CheckingAccount extends Account. A user may test a checkingAccount object to see if it is Debitable by asking checkingAccount.getClass().isAssignableFrom(Debitable.class)  before calling the debit() method on it.
Comment for this answer: actually isAssignableFrom() returns false for both the class and the super class when the interface is passed as the argument, my mistake.
Comment for this answer: However there is still a difference from the reflection viewpoint. This code snippet illustrates that.
CheckingAccount checkingAccount = new CheckingAccount();
Account account = new Account();
System.out.println("Checking Account assignable from Debitable:" + Arrays.asList(checkingAccount.getClass().getInterfaces()).contains(Debitable.class));
System.out.println("Account assignable from Debitable:" + Arrays.asList(account.getClass().getInterfaces()).contains(Debitable.class));
Comment for this answer: This is incorrect. `isAssignableFrom()` accomplishes the same thing as `instanceof`, and a reference variable for Z can certainly hold an object of type X in the OP's example regardless of whether or not X explicitly implements Z.
Comment for this answer: I'm not familiar with this method, and its purpose

Here is another answer: You can find a lot of such examples in java.util.*, for instance List -> ArrayList -> RoleList

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 3, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:03/04/14', 'FavoriteCount': 0.0, 'PostTypeId': 1, 'Tags': '<java><inheritance><polymorphism>', 'Title': 'Should a java class x that extends class y, which implements interface z, also implement interface z', 'ViewCount': 2855, 'id': 22174586, 'user_AboutMe': '<p>Student, Code and Programming Enthusiast</p>\n', 'user_AccountId': 2284159.0, 'user_DisplayName': 'piedpiper', 'user_Reputation': 1200.0, 'user_Views': 297.0, 'user_id': 2008597.0}}