Bird
0
0

Which of the following class definitions correctly shows multiple inheritance that can cause the diamond problem?

easy📝 Syntax Q12 of 15
Python - Multiple Inheritance and Method Resolution

Which of the following class definitions correctly shows multiple inheritance that can cause the diamond problem?

class A:
    pass

class B(A):
    pass

class C(A):
    pass

class D(??):
    pass

What should replace ???

AA, B
BB, C
CC, B
DA, C
Step-by-Step Solution
Solution:
  1. Step 1: Identify classes inheriting from A

    Classes B and C both inherit from A, so they form the upper branches of the diamond.
  2. Step 2: Define class D inheriting from B and C

    To create the diamond shape, D must inherit from both B and C.
  3. Final Answer:

    B, C -> Option B
  4. Quick Check:

    Diamond bottom inherits from both branches [OK]
Quick Trick: Diamond bottom class inherits from both intermediate classes [OK]
Common Mistakes:
  • Using A directly in D's inheritance
  • Swapping order without reason
  • Using only one parent class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes