Courseiva

PCAP Object-Oriented Programming Practice Question

Consider the following code snippet: 'class A: pass; class B(A): pass; class C(A): pass; class D(B, C): pass'. What is the Method Resolution Order (MRO) for class D according to the C3 linearization algorithm used by Python?

⚠ Common exam trap

Python Institute often tests the misconception that Python uses depth-first left-to-right resolution (like in old-style classes), leading candidates to pick Option A (D, B, A, C, object) instead of the correct C3 linearization result.

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

The C3 linearization algorithm merges the linearizations of D's parents (B and C) with their parent list, respecting the local precedence order and monotonicity. For class D(B, C), the MRO is computed as D + merge(L(B), L(C), [B, C]), where L(B) = B, A, object and L(C) = C, A, object. The merge yields D, B, C, A, object, which is the correct MRO.

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, A, C, object

    Why it's wrong here

    This order is what a naive depth-first, left-to-right traversal might produce, but C3 linearization does not allow it. In the merge step, after D and B are emitted, A cannot be taken because A appears in the tail of C's linearization [C, A, object]; the head C must be emitted first. Placing A before C also violates monotonicity, since C's own MRO [C, A, object] would not be a subsequence of [D, B, A, C, object], making attribute lookup inconsistent with C's declared inheritance.

  • ✗

    D, B, C, A

    Why it's wrong here

    This list is incomplete because every Python class ultimately inherits from object, and object must be the final entry in any MRO. C3 linearization always ends with object, as the merge process consumes all base-class tails down to the root. Omitting object would mean there is no terminal class for attribute lookup, so the MRO cannot be considered valid even if the relative order of D, B, C, and A is correct.

  • ✗

    D, B, A, object, C

    Why it's wrong here

    Placing object before C is impossible in a valid MRO because object is the ultimate superclass and must always appear after all of D's base classes. Since C is an immediate base of D, C must be emitted before object; otherwise C's own linearization [C, A, object] cannot be preserved as a subsequence. This order would cause attribute lookup to find nothing in C after object has been searched, breaking the inheritance contract.

  • ✓

    D, B, C, A, object

    Why this is correct

    This is the correct C3 linearization for D(B, C) where both B and C inherit from A. The merge begins with D, then picks B because it is not in any tail; A is skipped next because it appears in the tail of C's linearization, forcing C to be emitted before A. After C is consumed, A and object are safe to append. The result preserves both parent MROs as subsequences and honors both local precedence order (B before C) and monotonicity, yielding D, B, C, A, object.

About these practice questions

One of 421 original PCAP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.