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: • Java requires explicit conflict resolution when multiple interfaces provide the same default method signature. • The implementing class must override the method; otherwise, a compile-time error occurs. • Inside the overridden method, you can choose one interface's implementation, combine both implementations, or provide entirely new logic.

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.

Code Example:

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.