I understand that if a class implements several interfaces containing default methods of the same name, then we must override this method in the child class to explicitly determine what my method will do.
The problem is this: 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[]) {
Now interface A and B have a default method named "print", but I want to override the printing method of interface B - the one that returns the string, and leave A print as is. But this code does not compile if:
Overrides A.print The return type is incompatible with A.print()
Obviously, the compiler is trying to override the printing method, and I have no idea why!
source share