Question 128 of 511
Object-Oriented ProgrammingeasyMultiple ChoiceObjective-mapped

Quick Answer

The answer is 0, because the class variable remains unchanged in the class namespace. When an instance assigns `self.count = 5`, Python creates a new instance attribute that shadows the class variable within that instance’s namespace, leaving the original class-level `count` untouched at 0. This concept of class variable vs instance attribute shadowing is a frequent trap on the Certified Associate Python Programmer PCAP exam, where you must distinguish between reading a class attribute through an instance (which falls back to the class) and assigning to it (which creates a local instance attribute). The exam tests your understanding of Python’s attribute lookup order: instance namespace first, then class namespace. A common memory tip is to remember that assignment always writes to the instance, never to the class—think of it as “self dot equals creates a new local copy.” So even after `self.count = 5`, the class’s `count` remains 0, and any other instance or direct class access will still see the original value.

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 class defines a variable `count = 0`. An instance modifies `self.count = 5`. What is the value of `count` in the class namespace?

Question 1easymultiple 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

0, because the class variable remains unchanged.

Option A is correct because when an instance assigns `self.count = 5`, Python creates an instance attribute that shadows the class variable `count` in the instance's namespace. The class variable `count` remains unchanged at 0 in the class namespace, as instance attribute assignment does not modify class 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.

  • 0, because the class variable remains unchanged.

    Why this is correct

    Instance attribute shadows the class variable.

    Related concept

    Read the scenario before looking for a memorised answer.

  • 5, because the instance modified the class variable.

    Why it's wrong here

    Assignment to self creates an instance attribute.

  • 0, but the assignment raises an AttributeError.

    Why it's wrong here

    No error; it creates an instance attribute.

  • The class variable is deleted and the instance has 5.

    Why it's wrong here

    Class variable still exists.

Common exam traps

Common exam trap: answer the scenario, not the keyword

The trap here is that candidates mistakenly believe `self.count = 5` modifies the class variable, but Python's assignment semantics always create or update an instance attribute, leaving the class variable untouched.

Detailed technical explanation

How to think about this question

Under the hood, Python's attribute access follows the MRO (Method Resolution Order): `self.count` first checks the instance's `__dict__`, then the class's `__dict__`. Assignment via `self.count = 5` always writes to the instance's `__dict__`, never to the class's `__dict__`. This shadowing behavior is fundamental to Python's data model and is critical when designing mutable class-level defaults (e.g., lists) that can lead to unintended shared state.

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 cloud solutions architect for a retail company is evaluating services for a new workload. The correct answer here reflects best practice for the specific scenario described — not a general cloud recommendation. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Cloud exam questions reward reading the constraint carefully: the same technology can be right or wrong depending on the use case.

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: 0, because the class variable remains unchanged. — Option A is correct because when an instance assigns `self.count = 5`, Python creates an instance attribute that shadows the class variable `count` in the instance's namespace. The class variable `count` remains unchanged at 0 in the class namespace, as instance attribute assignment does not modify class 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 24, 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.