100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

What is an Interface Default Method Conflict?

What is an interface default method conflict in Java, why it happens, and how InterfaceName.super resolves it, with a working code example.

mediumQ122 of 226 in Object Oriented Programming Est. time: 5 minsLast updated:
Open Code Lab

Expected Interview Answer

An interface default method conflict happens when a class implements two or more interfaces that each declare a default method with the same signature, and the compiler cannot decide which body to inherit, forcing the class to explicitly override the method and resolve the ambiguity itself.

Java introduced default methods in interfaces so existing interfaces could gain new behavior without breaking every implementing class. But once an interface can carry a body, diamond-shaped inheritance becomes possible: a class implementing InterfaceA and InterfaceB, both defining default greet(), inherits two competing implementations. The compiler refuses to silently pick one, since that would be an arbitrary and dangerous guess about intent. The fix is for the implementing class to override the conflicting method and, inside it, explicitly choose a parent implementation using InterfaceA.super.greet() (or write fresh logic), which removes the ambiguity and makes the resolution visible in source.

  • Forces explicit, visible resolution instead of silent guessing
  • Preserves backward compatibility when interfaces evolve
  • Keeps multiple-interface implementation safe from hidden diamond bugs
  • Documents intent directly at the point of conflict

AI Mentor Explanation

Imagine a player is simultaneously registered under two league rulebooks, and both rulebooks define a default over-limit for bowlers, but the numbers disagree. The scorer cannot silently pick one rulebook’s number without risking a wrong result being recorded as official. The player’s captain must explicitly state which rule applies for this match, or write a custom rule combining both. That forced, visible decision is exactly what a Java class must do when two interfaces hand it conflicting default methods.

Step-by-Step Explanation

  1. Step 1

    Two interfaces declare the same default method

    Both InterfaceA and InterfaceB provide a default body for a method with an identical signature.

  2. Step 2

    A class implements both interfaces

    The compiler detects it now has two competing inherited implementations for the same method.

  3. Step 3

    Compilation fails on ambiguity

    Java refuses to guess; it raises a compile-time error until the class resolves the conflict explicitly.

  4. Step 4

    Override and disambiguate

    The class overrides the method and calls InterfaceA.super.method() or InterfaceB.super.method(), or supplies entirely new logic.

What Interviewer Expects

  • Correct explanation of why default methods enabled this conflict (diamond problem via interfaces)
  • Mention that the compiler forces an explicit override rather than picking automatically
  • Knowledge of the InterfaceName.super.method() syntax for calling a specific parent default
  • Awareness this is a compile-time error, not a silent runtime bug

Common Mistakes

  • Assuming Java arbitrarily picks one default method to apply
  • Confusing this with abstract method conflicts (which never have this ambiguity)
  • Forgetting the InterfaceName.super.method() syntax exists to call a specific interface default
  • Believing extending a class and implementing an interface with the same default causes the same conflict (class always wins there)

Best Answer (HR Friendly)

When a class implements two interfaces that both provide a default implementation for the same method, Java can’t decide which one to use, so it forces you to override that method yourself in the class and explicitly say which parent behavior you want, or write new logic entirely. It’s the compiler’s way of making sure ambiguous behavior never gets silently guessed at.

Code Example

Resolving a default method conflict
interface Flyer {
    default String move() { return "flying"; }
}

interface Swimmer {
    default String move() { return "swimming"; }
}

// class Duck implements Flyer, Swimmer {}  // compile error: conflicting defaults

class Duck implements Flyer, Swimmer {
    @Override
    public String move() {
        // Explicitly choose or combine the parent behaviors
        return Flyer.super.move() + " and " + Swimmer.super.move();
    }
}

System.out.println(new Duck().move()); // flying and swimming

Follow-up Questions

  • Why did Java add default methods to interfaces in the first place?
  • How is this different from the classic multiple-inheritance diamond problem in C++?
  • What happens if a class extends a class and implements an interface, and both define the same default method?
  • Can you call a grandparent interface default method through InterfaceName.super?

MCQ Practice

1. A class implements two interfaces with conflicting default methods of the same signature. What happens?

Java raises a compile-time error and requires the implementing class to explicitly override the method.

2. How does a class call a specific interface’s default implementation during resolution?

The InterfaceName.super.method() syntax explicitly invokes a named interface’s default implementation.

3. If a class extends a concrete class and implements an interface, both defining the same method signature, which wins by default?

"Class wins" — a concrete method inherited from a superclass always takes priority over an interface default with the same signature.

Flash Cards

Interface default method conflict, one line?Two implemented interfaces provide the same default method, and the compiler forces an explicit override.

How do you call a specific parent default?InterfaceName.super.method() inside the overriding method.

Is this a compile-time or runtime issue?Compile-time — Java will not build until it is resolved.

"Class wins" rule?A superclass’s concrete method always beats a conflicting interface default automatically.

1 / 4

Continue Learning