Bird
0
0

What happens if a class implements two interfaces that have the same default method signature?

easy📝 Conceptual Q1 of 15
Java - Interfaces
What happens if a class implements two interfaces that have the same default method signature?
AThe compiler automatically merges both default methods.
BThe class must override the default method to resolve the conflict.
CThe class inherits both default methods without any error.
DThe class inherits the default method from the first interface only.
Step-by-Step Solution
Solution:
  1. Step 1: Understand multiple inheritance of default methods

    When two interfaces have the same default method, the implementing class faces a conflict.
  2. Step 2: Resolve conflict by overriding

    The class must provide its own implementation to avoid ambiguity.
  3. Final Answer:

    The class must override the default method to resolve the conflict. -> Option B
  4. Quick Check:

    Conflict resolution = Override method [OK]
Quick Trick: Override conflicting default methods to avoid errors [OK]
Common Mistakes:
  • Assuming compiler merges methods automatically
  • Ignoring the need to override conflicting methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes