Diamond Problem in Interfaces
OOP DesignTechnical InterviewMediumLast asked 12 months ago
Sumerge interview question (Egypt) · stage: Technical Interview · domain: OOP Design · role: Software Engineer · difficulty: Medium · asked twice, last in October 2025
What they ask
The board technical interview (two or three engineers) covers databases, OOP and problem solving. In the OOP part they go past the four pillars and ask about the diamond problem, specifically in the context of interfaces with default methods.
Typical sequence:
- Why does Java forbid extending two classes but allow implementing many interfaces?
- Since Java 8 interfaces can carry default methods. If
FlyerandSwimmerboth declaredefault void move(), andDuck implements Flyer, Swimmer, what happens? - How do you resolve it, and how do you call one specific parent's version?
- How does C++ approach the same shape (virtual inheritance) and why is that more complicated?
Example
interface Flyer { default String move() { return "fly"; } }
interface Swimmer { default String move() { return "swim"; } }
class Duck implements Flyer, Swimmer {
@Override public String move() {
return Flyer.super.move() + " then " + Swimmer.super.move();
}
}
Without the override in Duck, the compiler rejects the class; that is the whole point of the question.
What they look for
- Knowing that the conflict is a compile-time error, not a runtime surprise, and the exact
Interface.super.method()syntax. - Explaining the rule "class wins over interface" when a superclass also defines the method.
- A view on design: default methods are for evolving APIs, not for multiple inheritance of state.