Phase 11 of 20 · Topic 11.4

Multiple Interface Inheritance & Diamond Problem Resolution

1Concept

When a class implements two interfaces that declare default methods with identical signatures, the compiler throws a diamond collision error. The implementing class MUST explicitly override the method and resolve ambiguity using `InterfaceName.super.method()` syntax.

2Architecture Diagram

Interface A: default void ping()        Interface B: default void ping()
                       \                           /
                        \                         /
                         [ Concrete Class C ]
                  MUST override ping() and choose:
                  A.super.ping() OR B.super.ping()

3Code Example

Core Java
public class DiamondProblemDemo {
    interface ServiceAlpha {
        default void status() {
            System.out.println("Alpha Service: Operational");
        }
    }

    interface ServiceBeta {
        default void status() {
            System.out.println("Beta Service: Operational");
        }
    }

    static class HybridSystem implements ServiceAlpha, ServiceBeta {
        // Explicitly resolving the diamond conflict
        @Override
        public void status() {
            ServiceAlpha.super.status(); // Explicitly invoke Alpha
            ServiceBeta.super.status();  // Explicitly invoke Beta
            System.out.println("Hybrid Coordinator: Fully Synchronized");
        }
    }

    public static void main(String[] args) {
        HybridSystem system = new HybridSystem();
        system.status();
    }
}

4Expected Output

Alpha Service: Operational
Beta Service: Operational
Hybrid Coordinator: Fully Synchronized

5Key Takeaways

  • Resolution syntax is strictly: `InterfaceName.super.methodName()`.
  • Diamond problem only applies to default method implementations, not abstract method signatures.
  • If a class extends a class AND implements an interface with same method, class implementation always wins.