Saturday, 31 August 2013

Only child class overrides interface methods in Java

Only child class overrides interface methods in Java

I know that each class that implements some Interface must override all
its methods. Except if current class is abstract.
As you can see under mentioned template of code demonstrates that.
IN my case only ChildClass overrides foo() method.
Interface
public interface MyItf {
public void foo();
}
Parent class
public abstract class ParentClass implements MyItf {
}
Child class
public class ChildClass extends ParentClass{
@Override
public void foo() {
}
}
But this implementation demands me to set ParentClass class to be abstract.
What if I want to leave ParentClass to be single class and not abstract?
Does anyone have other ways where only children use MyItf but not Parent
class?
Thank you,

No comments:

Post a Comment