Bird
0
0

What happens if two interfaces have methods with the same signature and a class implements both?

easy📝 Conceptual Q2 of 15
Java - Interfaces
What happens if two interfaces have methods with the same signature and a class implements both?
AThe class must override the method to resolve the conflict.
BJava throws a compile-time error automatically.
CThe class inherits both methods without conflict.
DThe class can only implement one of the interfaces.
Step-by-Step Solution
Solution:
  1. Step 1: Identify method conflict in multiple interfaces

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

    The class must provide its own implementation to resolve the conflict explicitly.
  3. Final Answer:

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

    Method conflict resolution = A [OK]
Quick Trick: Override conflicting methods when implementing multiple interfaces [OK]
Common Mistakes:
  • Assuming Java auto-resolves method conflicts
  • Ignoring the need to override conflicting methods
  • Thinking multiple inheritance is disallowed if methods clash

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes