Reputation: 3323
Assume there is a code as such:
package com.ps.Sample;
public interface Sample
{
public void Method1();
}
public abstract class AbstractSample implements Sample
{
public void Method1()
{
System.out.println("Hello World");
}
}
public class MySample extends AbstractSample
{
}
public class TestSample
{
public static void main(String[] args)
{
Sample my = new MySample();
my.Method1();
}
}
My question is: Is there any benefit to declaring the concrete class as
public class MySample extends AbstractSample implements Sample
instead of
public class MySample extends AbstractSample
Upvotes: 2
Views: 151
Reputation: 19225
One benefit would be that if AbstractSample was changed to not implement Sample, the first declaration would still allow you to pass instances of MySample to methods expecting a Sample.
Upvotes: 4
Reputation: 691645
No, there is not. It's redundant. AbstractSample is a Sample, and MySample is a AbstractSample. So MySample is a Sample.
The javadoc displays all the implemented interfaces anyway, whether you add the implements Sample
or not.
Upvotes: 9