Bird
Raised Fist0

Which design modification best mitigates this problem?

hard🔁 Follow-Up Q10 of Q15
OOP & Design Patterns - Inheritance - Types, Method Resolution Order & Diamond Problem
In a programming language lacking built-in Method Resolution Order (MRO), you observe that multiple inheritance causes ambiguous method calls at runtime. Which design modification best mitigates this problem?
ARemove all multiple inheritance and use only single inheritance
BManually override conflicting methods in the subclass to explicitly specify which parent method to call
CRely on the compiler to automatically choose the first declared parent method
DUse global variables to track which method should be called
Step-by-Step Solution
Solution:
  1. Step 1: Identify the cause

    Without built-in MRO, method call ambiguity arises in multiple inheritance.
  2. Step 2: Choose a design fix

    Manually overriding conflicting methods in the subclass clarifies which parent method to invoke.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Explicit overrides resolve ambiguity without MRO [OK]
Quick Trick: Explicit overrides clarify method calls without MRO [OK]
Common Mistakes:
MISTAKES
  • Assuming compiler auto-resolves conflicts
  • Eliminating multiple inheritance unnecessarily
  • Using global variables for method resolution
Trap Explanation:
PITFALL
  • Option B is too restrictive; Option C is incorrect as compiler may not auto-resolve; Option D is unrelated and unsafe.
Interviewer Note:
CONTEXT
  • Tests ability to design around lack of MRO in multiple inheritance scenarios.
Master "Inheritance - Types, Method Resolution Order & Diamond Problem" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes