Question 395 of 511
Object-Oriented ProgramminghardMultiple ChoiceObjective-mapped

Quick Answer

The correct answer is that the descriptor protocol activates only when the attribute is a class variable and the descriptor object is defined in the class dictionary. This happens because Python’s data model prioritizes instance attributes stored in `__dict__` over non-data descriptors, but data descriptors (those implementing `__set__` or `__delete__`) override instance `__dict__`. The key technical concept is the descriptor protocol condition: for `__get__` or `__set__` to be invoked, the attribute must be accessed on the class, not directly on the instance’s own dictionary. On the PCAP exam, this tests your understanding of attribute lookup precedence and the distinction between data and non-data descriptors. A common trap is assuming any object with `__get__` always triggers the protocol, but instance attributes shadow non-data descriptors. Remember the memory tip: “Class variable, protocol active; instance variable, protocol inactive—unless it’s a data descriptor, which overrides the instance.”

PCAP Object-Oriented Programming Practice Question

This PCAP practice question tests your understanding of object-oriented programming. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

A developer implements a descriptor class with `__get__` and `__set__` methods. When an instance attribute is accessed, what determines whether the descriptor is used?

Question 1hardmultiple choice
Full question →

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

The descriptor is used only if the attribute is a class variable and the descriptor protocol is implemented.

Option D is correct because in Python, the descriptor protocol (__get__, __set__, __delete__) is only invoked when the attribute is accessed on the class (i.e., it is a class variable) and the descriptor object is defined in the class dictionary. Instance-level attributes stored in __dict__ take precedence over descriptors, so the descriptor is ignored if the instance has its own attribute with the same name. This behavior is defined by the Python data model: data descriptors (with __set__ or __delete__) override instance __dict__, but non-data descriptors (only __get__) are shadowed by instance attributes.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • The descriptor's `__get__` is called only if `__getattr__` is not defined.

    Why it's wrong here

    Descriptors are independent of __getattr__.

  • If the attribute exists in the instance's __dict__, the descriptor is ignored.

    Why it's wrong here

    Instance attribute always takes precedence.

  • The descriptor must be defined in the class's metaclass.

    Why it's wrong here

    No, it's defined as a class variable.

  • The descriptor is used only if the attribute is a class variable and the descriptor protocol is implemented.

    Why this is correct

    Correct: descriptors are class variables that override access.

    Related concept

    Read the scenario before looking for a memorised answer.

Common exam traps

Common exam trap: answer the scenario, not the keyword

Python Institute often tests the distinction between data and non-data descriptors, and the trap here is that candidates assume instance __dict__ always wins, forgetting that data descriptors (with __set__) override instance attributes.

Detailed technical explanation

How to think about this question

Under the hood, Python's attribute lookup follows a specific order: for instance attribute access, it first checks the class's __mro__ for data descriptors, then the instance's __dict__, then non-data descriptors, and finally __getattr__ if all else fails. A common subtlety is that if a descriptor defines only __get__ (non-data descriptor), an instance attribute with the same name will shadow it, which can lead to surprising behavior when using properties or methods as descriptors. In real-world code, this is why @property (a data descriptor) always overrides instance attributes, while functions (non-data descriptors) can be overridden by instance attributes like lambdas or bound methods.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A media company stores terabytes of video archives that are accessed once a year for audit purposes. Moving these objects to a cold storage tier (Azure Archive, S3 Glacier, or Google Nearline) costs a fraction of hot storage. Questions like this test whether you understand storage tiers, access frequency tradeoffs, and retrieval latency requirements.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related PCAP practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free PCAP practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this PCAP question test?

Object-Oriented Programming — This question tests Object-Oriented Programming — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: The descriptor is used only if the attribute is a class variable and the descriptor protocol is implemented. — Option D is correct because in Python, the descriptor protocol (__get__, __set__, __delete__) is only invoked when the attribute is accessed on the class (i.e., it is a class variable) and the descriptor object is defined in the class dictionary. Instance-level attributes stored in __dict__ take precedence over descriptors, so the descriptor is ignored if the instance has its own attribute with the same name. This behavior is defined by the Python data model: data descriptors (with __set__ or __delete__) override instance __dict__, but non-data descriptors (only __get__) are shadowed by instance attributes.

What should I do if I get this PCAP question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Keep practising

More PCAP practice questions

Last reviewed: Jun 30, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.