Core Java: A diamond conflict between two default methods forces an explicit override

When a class implements two interfaces with the same default method, it must override that method itself, and can pick a specific parent's version with Interface.super.method().

Code
interface A { default String who() { return "A"; } }
interface B { default String who() { return "B"; } }
class C implements A, B {
    @Override
    public String who() {
        return A.super.who() + B.super.who();
    }
}
System.out.println(new C().who());
Output
AB
Advertisement
More in JAVA

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-09-27

© Java Coding Hub · About · Contact · Privacy · Terms