Why does Java not allow a class to extend two classes? How do default methods in interfaces bring the "diamond problem" back, and how is it resolved?
Show the explanation
If class C could extend both A and B, and both defined hello() (or both inherited a field from a common parent), it would be ambiguous which one C gets — the diamond problem. Java avoids it by allowing one superclass but many interfaces.
Since Java 8, interfaces can have default methods, so the ambiguity can appear again. Java resolves it with rules: (1) a method in a class wins over interface defaults; (2) a more specific interface wins over the one it extends; (3) otherwise the class must override the method, and can pick one with Interface.super.method():
interface Camera { default String start() { return "camera on"; } }
interface Phone { default String start() { return "phone on"; } }
class SmartPhone implements Camera, Phone {
@Override public String start() { // required: otherwise a compile error
return Phone.super.start() + " + " + Camera.super.start();
}
}Because interfaces carry no instance fields, there is no ambiguity about state, only about behaviour — and the compiler makes you settle it explicitly.
Original UniCircle question. Last reviewed 22 Oct 2026.
