I'm tying to understand why the following (example 1 below) gives me a compiler error stating that...
'ClassA inherits abstract and default for test() from types Interface1 and Interface2'
...when if I change Interface1 to an abstract class and have AClass extend it, (while still implementing Interface2), it behaves as I would expect (no compiler error).
My understanding is that abstract methods have a higher precedence than that of default methods. In other words, I would expect example 1 to compile, just as example2 does - and for any concrete class(es) derived from AClass to have to provide implementation for the test() method. In both examples, if I remove 'abstract' from ClassA's definition, I get a compiler error (as expected) because I'm not providing that implementation. Why though, when AClass is abstract does it not compile when implementing the 2 interfaces but does when extending ASupClass and implementing Interface2? Why the difference?
Code Example 1 (With 2 interfaces)
abstract class AClass implements Interface1, Interface2{ //Compiler error
}
interface Interface1{
public abstract String test();
}
interface Interface2{
default String test(){return "";}
}
Code Example 2 (with 1 abstract class and 1 interface)
abstract class AClass extends ASupClass implements Interface2{ //No compiler error
}
abstract class ASupClass{
public abstract String test();
}
interface Interface2{
default String test(){return "";}
}