David Corneth wrote:"If a class implements two interfaces that have default methods with the same name and signature, the compiler will throw an error."
Here default methods of those two interfaces having same signature are inherited ergo compiler finds ambiguity which one is going to be used by Cat class ( method of Walk Or Run ) so gives compile time error.
Then the book states there is one exception to this rule and lists it;
"if the subclass overrides the duplicate default methods, the compiler will compile without issue-..."
Here subclass i.e. Cat provides It's own implementation of method getSpeed() by overriding It, now compiler knows which version of getSpeed() method (method provided by Cat class) is going to be used so compiles successfully.
But
I'd think there is another exception; if one interface extends the other then the compiler will run without issue.
Consider the following code: This compiles without error and prints 2.
I don't think so because there is no ambiguity while calling getSpeed method in above example because getSpeed method of interface i1 is overridden by getSpeed method of i2 since both have same signature, therefore compiler knows getSpeed method of interface i2 is going to be used so gives no compile time error and prints 2.