PCAP Object-Oriented Programming Practice Question
A class named Counter has a class variable count and an instance method increment. The method is defined as def increment(self): Counter.count += 1. What will be the output after executing the following code? c1 = Counter(); c2 = Counter(); c1.increment(); c2.increment(); print(Counter.count, c1.count, c2.count)
⚠ Common exam trap
Python Institute often tests the distinction between class variables and instance variables, trapping candidates who mistakenly think each instance gets its own copy of the class variable or that `self.count` would create an instance attribute instead of modifying the class variable.
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
✓
2 2 2
The class variable `count` is shared across all instances of the `Counter` class. The `increment` method modifies `Counter.count` directly, so after two calls, `Counter.count` becomes 2. Since `c1.count` and `c2.count` refer to the same class variable (they do not have instance attributes shadowing it), both instances reflect the same value of 2.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
2 2 2
Why this is correct
The output is 2 2 2 because `count` is a class variable defined on the `Counter` class. Each call to `increment()` modifies the same class-level attribute, not a per-instance copy, so after two increments the shared value becomes 2. Both `c1.count` and `c2.count` resolve to that same class attribute via Python's attribute lookup chain, and `Counter.count` directly reads it, so all three expressions print the identical value 2.
- ✗
2 1 1
Why it's wrong here
The value 2 1 1 would imply that `c1` and `c2` somehow hold different copies of `count`, but no instance attribute named `count` is ever assigned. Because `count` is declared in the class body, it is shared by all instances; any lookup that finds it on the class returns the same underlying object. Since both instances reference the same class variable, their values cannot diverge into 1 and 2.
- ✗
1 1 1
Why it's wrong here
The output 1 1 1 would only be possible if exactly one increment had occurred before the `print` statement. The scenario, however, performs two separate calls to `increment()`, each of which adds 1 to the same shared class variable. Starting from 0 and incrementing twice inevitably yields 2, so reporting 1 for every reference ignores one of the two mutations.
- ✗
0 0 0
Why it's wrong here
The output 0 0 0 represents the initial value of `count` before any method calls, but the code already executed both `increment()` calls by the time `print` runs. Class variables do not reset themselves or remain unchanged when explicitly incremented; each call permanently updates the single class-level binding. Therefore, 0 is only the starting state, not the final state.
Go deeper
Related to this question
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 →
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.