PCAP Object-Oriented Programming Practice Question
Exhibit
class A:
def method(self):
return 'A'
class B(A):
def method(self):
return 'B'
class C(A):
def method(self):
return 'C'
class D(B, C):
pass
print(D.mro())Refer to the exhibit. Which of the following correctly shows the MRO of class D?
⚠ Common exam trap
Python Institute often tests the C3 linearization rule that the local precedence order (the order of bases in the class definition) must be preserved, so candidates mistakenly reorder bases based on inheritance depth rather than the explicit left-to-right order in the class statement.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
[D, B, C, A, object]
Python's Method Resolution Order (MRO) for class D, which inherits from B and C (where B inherits from A and C inherits from A), follows the C3 linearization algorithm. The MRO is computed as D -> B -> C -> A -> object, ensuring that each class appears before its parents and that the order respects the local precedence order of D's bases (B before C).
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
[D, B, C, A, object]
Why this is correct
This is the exact output of C3 linearization for a diamond hierarchy where D inherits from B and C, and both B and C inherit from A. The merge step first takes D, then B because it is the head of the first base list and appears in no other list's tail, then C (not A, because A is in the tail of C's list), and finally A and object. This preserves both local precedence (B before C) and monotonicity (each base's own MRO is a subsequence of D's).
- ✗
[D, A, B, C, object]
Why it's wrong here
This order places A before B, even though B is a direct subclass of A and appears earlier in its own MRO. C3 requires that every class appear after its subclasses, and it also requires monotonicity: D's MRO must preserve the order B → A from B's MRO. By putting A before B, this ordering violates both constraints, so the merge algorithm would reject it.
- ✗
[D, B, A, C, object]
Why it's wrong here
Here B appears before A, which satisfies B's linearization, but C is erroneously placed after A. Since C is a subclass of A, C must precede A in any valid MRO, and C's own MRO (C, A, object) must remain a subsequence. The C3 merge would never select A before C while C is still available, because A is in the tail of C's list and therefore blocked until C is consumed.
- ✗
[D, C, B, A, object]
Why it's wrong here
This ordering swaps the direct bases of D, placing C before B even though D is declared as class D(B, C). The 'local precedence order' rule in C3 strictly preserves the left-to-right order of base classes in the class statement. Reversing B and C violates that rule, even though the rest of the chain (A, object) is correct, so this would not be produced by Python's MRO.
Go deeper
Related to this question
About these practice questions
This PCAP question is part of Courseiva's 421-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.