Challenge - 5 Problems
Multiple Inheritance Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of method resolution order (MRO) in multiple inheritance
What is the output of this Python code showing the method resolution order (MRO) for classes with multiple inheritance?
Python
class A: pass class B(A): pass class C(A): pass class D(B, C): pass print(D.__mro__)
Attempts:
2 left
💡 Hint
Remember Python uses C3 linearization for MRO in multiple inheritance.
✗ Incorrect
Python's MRO for class D with parents B and C is D, B, C, A, object. This order respects the inheritance hierarchy and avoids conflicts.
❓ Predict Output
intermediate2:00remaining
Output of method calls in diamond inheritance
What is the output of this code demonstrating method calls in diamond multiple inheritance?
Python
class A: def greet(self): return 'Hello from A' class B(A): def greet(self): return 'Hello from B' class C(A): def greet(self): return 'Hello from C' class D(B, C): pass obj = D() print(obj.greet())
Attempts:
2 left
💡 Hint
Check which parent class appears first in the inheritance list of class D.
✗ Incorrect
Class D inherits from B and C. Since B is first, its greet method is called due to Python's MRO.
🔧 Debug
advanced2:00remaining
Identify the error in multiple inheritance with conflicting methods
What error does this code raise when trying to create an instance of class D?
Python
class A: def action(self): return 'Action from A' class B: def action(self): return 'Action from B' class D(A, B): pass obj = D() print(obj.action())
Attempts:
2 left
💡 Hint
Check if the classes A and B have a common ancestor and how Python resolves method calls.
✗ Incorrect
Python resolves method calls using MRO. Since A is first in inheritance, its action method is called without error.
📝 Syntax
advanced2:00remaining
Which option causes a syntax error in multiple inheritance?
Which of the following class definitions will cause a syntax error?
Attempts:
2 left
💡 Hint
Check the syntax for listing multiple base classes in Python.
✗ Incorrect
In Python, multiple base classes must be separated by commas. Missing comma causes syntax error.
🚀 Application
expert3:00remaining
Determine the final output with super() in multiple inheritance
What is the output of this code that uses super() in a multiple inheritance scenario?
Python
class A: def process(self): return 'A' class B(A): def process(self): return super().process() + 'B' class C(A): def process(self): return super().process() + 'C' class D(B, C): def process(self): return super().process() + 'D' obj = D() print(obj.process())
Attempts:
2 left
💡 Hint
Trace the calls following Python's MRO and how super() delegates method calls.
✗ Incorrect
The MRO is D, B, C, A, object. Each process calls super().process() adding its letter. So output is A + C + B + D = 'ACBD'.