Implementing interfaces in an abstract class
suggest changeA method declared in an interface with no body is public abstract. A static interface method is not abstract and is not inherited. When an abstract class implements an interface, it does not have to implement the interface's abstract methods, because an abstract class may leave methods abstract. The first concrete subclass must implement every abstract method inherited from the interfaces and from the abstract class. The three public types below cannot share one source file.
public interface NoiseMaker {
void makeNoise();
}
public abstract class Animal implements NoiseMaker {
//Does not need to declare or implement makeNoise()
public abstract void eat();
}
//Because Dog is concrete, it must define both makeNoise() and eat()
public class Dog extends Animal {
@Override
public void makeNoise() {
System.out.println("Borf borf");
}
@Override
public void eat() {
System.out.println("Dog eats some kibble.");
}
}
From Java 8 onward it is possible for an interface to declare default implementations of methods which means the method won’t be abstract, therefore any concrete sub-classes will not be forced to implement the method but will inherit the default implementation unless overridden.