Question 240 of 511
Object-Oriented ProgrammingeasyMultiple SelectObjective-mapped

Quick Answer

The answer is the `@property` decorator and the `property()` built-in function. The `@property` decorator transforms a method into a managed attribute getter, allowing you to define read-only properties concisely, while `property(getter, setter)` creates a property object that you assign as a class variable, giving you explicit control over both getter and setter behavior. On the PCAP exam, this question tests your understanding of Python’s descriptor protocol and how properties enforce encapsulation without breaking backward compatibility. A common trap is confusing `@property` with a regular method call or thinking only one syntax is valid—remember that both are officially supported ways to define a property. For a memory tip, think of `@property` as the “sugar” for simple read-only access and `property()` as the “full recipe” when you need custom getter/setter logic.

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.

Which TWO of the following are valid ways to define a property in a Python class? (Select exactly 2.)

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

Use `property(getter, setter)` as a class variable.

Option D is correct because `property(getter, setter)` is a built-in function that returns a property object, which can be assigned as a class variable to define a managed attribute. Option E is correct because the `@property` decorator is the standard, concise way to define a read-only property by decorating a method that acts as the getter.

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.

  • Define a method named `property` inside the class.

    Why it's wrong here

    That would just define a method, not a property descriptor.

  • Override `__getattribute__` and check the attribute name.

    Why it's wrong here

    That affects all attribute access, not an isolated property.

  • Override `__getattr__` to simulate a property.

    Why it's wrong here

    __getattr__ is a fallback for missing attributes, not a property.

  • Use `property(getter, setter)` as a class variable.

    Why this is correct

    Correct: property() creates a property descriptor.

    Related concept

    Read the scenario before looking for a memorised answer.

  • Use the @property decorator on a method.

    Why this is correct

    Correct: @property makes a method act as a read-only attribute.

    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 defining a property via the `property()` function or `@property` decorator versus overriding dunder methods like `__getattr__` or `__getattribute__`, which are attribute interception hooks, not property definitions.

Detailed technical explanation

How to think about this question

Under the hood, `property()` creates a descriptor object that implements `__get__`, `__set__`, and `__delete__` methods, which are invoked by Python's attribute lookup protocol. The `@property` decorator is syntactic sugar for `property(getter)`, and when used with `@x.setter` and `@x.deleter`, it builds a full descriptor. A subtle behavior is that properties defined on a class are only invoked for instance attribute access, not class-level access, which can lead to confusion when debugging.

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: Use `property(getter, setter)` as a class variable. — Option D is correct because `property(getter, setter)` is a built-in function that returns a property object, which can be assigned as a class variable to define a managed attribute. Option E is correct because the `@property` decorator is the standard, concise way to define a read-only property by decorating a method that acts as the getter.

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

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.