Consider the following code:
interface IParent {
default void print() {
System.out.println("Interface");
}
}
class Parent {
public void print() {
System.out.println("Class");
}
}
class Child extends Parent implements IParent {
public static void main(String []args) {
Child c = new Child();
c.print(); //prints Class
}
}
Why does calling the print() method output Class?
I know for sure that if Parent was interface instead of class declared the print() method as default, then compiler error would be generated due to duplicate print() methods being inherited by the Child class.
But why does this work and why is it that Parent's method is called and not IParent's?