Bird
Raised Fist0

Consider this code:

hard🚀 Application Q9 of Q15
Python - Multiple Inheritance and Method Resolution
Consider this code:
class A:
    def process(self):
        return 'A'
class B(A):
    def process(self):
        return 'B'
class C(A):
    def process(self):
        return 'C'
class D(B, C):
    def process(self):
        return super().process()
class E(C, B):
    def process(self):
        return super().process()
class F(D, E):
    pass
print(F().process())

What is the output of F().process()?
ATypeError due to inconsistent MRO
BB
CC
DA
Step-by-Step Solution
Solution:
  1. Step 1: Analyze inheritance of F

    F inherits from D and E; D and E have conflicting base class orders (B, C vs C, B).
  2. Step 2: Check MRO consistency

    Python cannot create a consistent MRO for F, raising TypeError.
  3. Final Answer:

    TypeError due to inconsistent MRO -> Option A
  4. Quick Check:

    Conflicting base class order causes TypeError [OK]
Quick Trick: Conflicting base class order breaks MRO, causing TypeError [OK]
Common Mistakes:
MISTAKES
  • Expecting normal output
  • Ignoring MRO conflict

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes