Courseiva
Object-Oriented Programming →mediumMultiple Choice

PCAP Method Resolution Order (MRO) Practice Question

A developer defines a class hierarchy with multiple inheritance: class A, class B(A), class C(A), class D(B,C). The method 'm' is defined only in A. What is the method resolution order for D according to the C3 linearization algorithm?

⚠ Common exam trap

Python Institute often tests the misconception that the MRO follows a simple depth-first left-to-right order, causing candidates to pick option D (D, B, A, C) instead of the correct C3 merge result. Additionally, candidates may forget that 'object' is always included in the MRO, leading them to choose option C over B.

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

B is correct because the C3 linearization algorithm always includes 'object' at the end of the MRO. For class D(B, C), L(D) = D + merge(L(B), L(C), [B, C]). L(B) = B, A, object; L(C) = C, A, object. Merge yields D, B, C, A, object. Options that omit 'object' (like C) are incomplete.

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 -> object

    Why it's wrong here

    This MRO drops class C entirely, which is impossible in Python: C3 linearization must include every class in the inheritance graph exactly once. Because D(B, C) lists C as a direct base, C is a required member of D's MRO. Moreover, since C(A) makes A a superclass of C, C must appear before A in any valid MRO; this order places A before C and therefore violates both completeness and the C3 merge rules.

  • ✓

    D -> B -> C -> A -> object

    Why this is correct

    This is the correct C3 linearization. For D(B, C), B(A), C(A), and A(object), the merge starts with D, then B's MRO [B, A, object] and C's MRO [C, A, object] are merged with the direct bases [B, C]. B is taken first, then C (because C is not in the tail of B's MRO), then A (because A is not in the tail of any remaining list), and finally object. This order preserves local precedence order (B before C), respects the inheritance chain C before A, and includes object as the final class.

  • ✗

    D -> B -> C -> A

    Why it's wrong here

    This order is just the correct MRO with 'object' removed, but Python's MRO must always terminate with the 'object' class. Every class hierarchy ultimately inherits from object, so C3 linearization includes object as the last class in every MRO. Omitting object would make the sequence incomplete and would break the guarantee that attribute lookup on any instance eventually reaches the built-in object class.

  • ✗

    D -> B -> A -> C

    Why it's wrong here

    This order fails local precedence order because D is defined as D(B, C), which requires B to be merged before C. Even though B and A are both present, the linearization places A before C, and since C(A) means C is a subclass of A, C must appear before A in D's MRO. An order with B, A, C is not consistent with the C3 merge of [B, A, object] and [C, A, object], because A appears in the tail of C's MRO and cannot be selected while C remains pending.

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 →

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.