J.II · Java 25 practice question

A developer defines an interface that extends two superinterfaces declaring override-equivalent methods, where one is a default method and the other is abstract. What happens when this Java 25 source file is compiled?

interface A {
    default String label() { return "A"; }
}
interface B {
    String label();
}
interface C extends A, B {}
void main() {
    IO.println("ok");
}
Choose one answer
Check answer and explanation

Correct answer: Compilation fails because the subinterface inherits a default method whose signature is override-equivalent with another inherited method.

Explanation

Compilation fails because an interface cannot inherit a default method that is override-equivalent with another inherited method, even when the second method is abstract. The subinterface must explicitly declare its own overriding method to resolve the conflict.

Common trap

Developers often assume a default implementation automatically fills in an inherited abstract method, but Java requires an explicit override in the subinterface. Treating the conflict as implicitly abstract is a common misconception; the compiler rejects the declaration instead.

Source: JLS SE 25 §9.4.1.3. Inheriting Methods with Override-Equivalent Signatures
Checked against the cited text on 2026-11-25.

Report an error in this question