Bird
Raised Fist0

How does the MRO affect which method is called when the child class method calls super()?

hard🎤 Interviewer Follow-up Q15 of Q15
OOP & Design Patterns - Inheritance - Types, Method Resolution Order & Diamond Problem
In a language that supports multiple inheritance with MRO, what happens if two parent classes define a method with the same name, but one parent class inherits from the other (forming a diamond), and the child class overrides that method? How does the MRO affect which method is called when the child class method calls super()?
Asuper() follows the MRO linearization, calling the next method in the MRO sequence, which may skip some classes.
Bsuper() calls the method from the immediate parent class only, ignoring the diamond structure.
Csuper() calls all parent methods with the same name in parallel, combining their effects.
Dsuper() always calls the method from the base class at the top of the diamond first.
Step-by-Step Solution
  1. Step 1: Understand super() in multiple inheritance

    super() does not simply call the immediate parent but follows the MRO linearization.
  2. Step 2: MRO linearization

    MRO creates a linear order of classes to avoid ambiguity and duplication, so super() calls the next method in this order.
  3. Step 3: Eliminate incorrect options

    super() calls the method from the immediate parent class only, ignoring the diamond structure is incorrect because super() is not limited to immediate parent. super() calls all parent methods with the same name in parallel, combining their effects is wrong because super() does not call methods in parallel. super() always calls the method from the base class at the top of the diamond first is incorrect because super() does not always start at the base class.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    super() respects MRO linearization, ensuring consistent method calls in diamond inheritance.
Quick Trick: super() = next in MRO chain
Common Mistakes:
MISTAKES
  • Thinking super() calls only immediate parent
  • Believing super() calls all parents simultaneously
  • Assuming super() always calls base class first
Trap Explanation:
PITFALL
  • Options B, C, and D reflect naive or incorrect views of super(), while A correctly describes super() behavior in MRO context.
Interviewer Note:
CONTEXT
  • Tests expert understanding of super() and MRO interaction in complex inheritance.
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