I understand that if a class implements multiple interfaces containing default methods of same name, then we need to override that method in the child class so as to explicitly define what my method will do.
Problem is, see the below code :
interface A {
default void print() {
System.out.println(" In interface A ");
}
}
interface B {
default String print() {
return "In interface B";
}
}
public class C implements A, B {
@Override
public String print() {
return "In class C";
}
public static void main(String arg[]) {
// Other funny things
}
}
Now interface A and B both have a default method with name 'print' but I want to override the print method of interface B - the one that returns a string and leave A's print as is. But this code doesn't compile giving this :
Overrides A.print
The return type is incompatible with A.print()
Clearly compiler is trying to override A's print method, and I have no idea why !