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):
passRefer to the exhibit. Which THREE statements about the class hierarchy are correct?
⚠ Common exam trap
Python Institute often tests the misconception that `super()` always calls the immediate parent class, when in fact it follows the MRO of the runtime instance, which can skip or reorder classes in multiple inheritance scenarios.
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
✓
Calling D().method() returns 'B'
When `D().method()` is called, Python's MRO (Method Resolution Order) for class D is `['D', 'B', 'C', 'A', 'object']`. Since class D does not define `method`, Python looks up the MRO and finds `method` first in class B. The `return 'B'` in B's `method` is executed, so the call returns 'B'.
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 does not have a method named 'method'
Why it's wrong here
D does not have a method named 'method' is wrong because D's class body is empty, but attribute lookup follows the method resolution order. When Python executes D().method(), it searches D first, then B, where it finds B.method, and binds that function to the instance. Thus D does have an accessible method named 'method' through inheritance, even though it is not lexically defined inside class D.
- ✓
Calling D().method() returns 'B'
Why this is correct
Calling D().method() returns 'B' because the MRO for D is ['D', 'B', 'C', 'A', 'object']. Since D defines no method, Python's lookup proceeds to B, whose method returns the string 'B' directly, without calling super(). Therefore C.method is never reached, and the call evaluates to the string 'B'.
- ✗
The super() call in B would call C.method
Why it's wrong here
The statement that the super() call in B would call C.method is incorrect because B's method body simply returns 'B' and contains no super() expression. If B.method had included super().method(), then on a D instance the next class in the MRO after B would indeed be C; however, because no such super() call exists in the implementation, this hypothetical behavior never occurs.
- ✓
The MRO of D is ['D', 'B', 'C', 'A', 'object']
Why this is correct
The MRO of D is ['D', 'B', 'C', 'A', 'object'] is correct. C3 linearization builds this order by taking D first, then merging the linearization of B (B, A, object) and the linearization of C (C, A, object), while preserving D's declared base order, B before C. A appears only once, after C, and object is last, yielding a consistent and monotonic MRO.
- ✓
Class C is a subclass of A
Why this is correct
Class C is a subclass of A because the class definition C(A) explicitly declares A as its base, so C inherits all of A's attributes and issubclass(C, A) returns True. This is a direct inheritance relationship, independent of the diamond structure created by D(B, C). The fact that C appears in D's MRO after B is a separate consequence of D's base order and C3 merging.
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.