Consider the following scenario: You have two interfaces with the same default method signature but different method bodies. How would you resolve this diamond problem when a class implements both interfaces?

When a class implements multiple interfaces that define the same default method, Java cannot automatically determine which implementation should be used. To eliminate this ambiguity, the implementing class must explicitly override the conflicting method and provide its own implementation. Within the overridden method, it can invoke a specific interface's default implementation using the InterfaceName.super.methodName() syntax.

Key Points

Example

Suppose Vehicle and ElectricVehicle interfaces both define a default start() method. A class implementing both interfaces must override start() and explicitly decide which behavior should be executed.

interface Vehicle {

    default void start() {
        System.out.println("Vehicle Started");
    }
}

interface ElectricVehicle {

    default void start() {
        System.out.println("Electric Vehicle Started");
    }
}

class Tesla implements Vehicle, ElectricVehicle {

    @Override
    public void start() {

        ElectricVehicle.super.start();

        // Or provide custom logic here
    }
}

public class Main {

    public static void main(String[] args) {

        Tesla car = new Tesla();
        car.start();
    }
}

Interview Tip

A concise interview answer is: When two interfaces contain the same default method, the implementing class must override that method to resolve the conflict. Inside the overridden method, a specific interface's implementation can be invoked using InterfaceName.super.methodName(), or custom behavior can be provided.

Last updated: 16 July 2026

Previous question: You have two classes, ClassA and ClassB, each dependent on the other. Both classes' constructors require the other class as a parameter. How would you resolve this circular dependency in Java?

Next question: How can we implement an LRU (Least Recently Used) cache using a LinkedList?

More Core Java - Level IV (Advanced) interview questions

All Core Java - Level IV (Advanced) questions