I can understand An interface can redeclare a default method and provide a different implementation. because it works like an Override.
But I don't understand the reasoning behind An interface can redeclare a default method and also make it abstract. I can just memorize this fact for the test, but It would be easy to forget if I do not understand the reasoning behind this.
Below are my hypothesis:
1. Because abstract and default keywords can go together -> WRONG. The book also states, "a method cannot be default as well as abstract at the same time".
Code: Select all
//abstract default String getId(); //1 Will not compile
//default abstract String getId(); //2 Will not compile
Code: Select all
//public default String getId(); //3 Will not compile because the kw [i]default[/i] is present
Adding @Override allows the code to compile fine
4. Because the child method only has the same name, but is a completely new method. -> WRONG
Code: Select all
void getId(); //Changing the child method return type. This is treated as an Override and requires a covariant return type, so it will not compile.
5b. Unlike accessibility modifiers(private, package, protected, public), the keywords abstract and default do not affect Overridability whatsoever?
Are my reasonings in #5 and #5b correct? If not, then can you explain the concept behind
An interface can redeclare a default method and also make it abstract.
a little bit more?
Thanks.