What individual changes, if any, would allow the following code to compile?
(Choose all that apply)
1: public interface Printable { public default String getName() { return null; } } 2: interface Displayable { public default String getName() { return null; } } 3: abstract class Otter implements Displayable, Printable {}
getName()
method with an abstract method in the Otter class. getName()
method with a concrete method in the Otter class. D, F, G.
The code does not compile, since a class cannot inherit two interfaces that both define default methods with the same signature, unless the class implementing the interfaces overrides it with an abstract or concrete method.
Therefore, option A is incorrect and options F and G are correct.
The alternate approach is to make the getName()
method abstract in the interfaces, because an interface may inherit two abstract methods with the same signature.
The change must be made to both interfaces, though, so options B and C are incorrect if taken individually.
option D is correct since the changes are taken together.