PCAP Object-Oriented Programming Practice Question
A developer defines a class 'Car' with an attribute 'wheels = 4'. They create two instances: car1 = Car() and car2 = Car(). Then they set car1.wheels = 3. What is the value of car2.wheels?
⚠ Common exam trap
Python Institute often tests the distinction between class attributes and instance attributes, trapping candidates who mistakenly think that modifying an instance attribute propagates to other instances or that it raises an error.
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
✓
4
In Python, setting an attribute directly on an instance (car1.wheels = 3) creates an instance attribute that shadows the class attribute for that specific instance only. The class attribute 'wheels = 4' remains unchanged and is still accessible via car2.wheels, which has not been overridden. Therefore, car2.wheels retains the class-level value of 4.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
4
Why this is correct
Since car2 never receives an instance attribute named wheels, Python's attribute lookup falls back to the class attribute defined on Car. At the time car2.wheels is evaluated, that class attribute still holds the integer 4, because the assignment car1.wheels = 3 only adds an entry to car1's __dict__, leaving the class-level value untouched. Therefore the correct result is 4, not 3, None, or an error.
- ✗
3
Why it's wrong here
The value 3 would only be visible if you inspected car1's own attribute after the assignment, because car1 now has an instance attribute that shadows the class attribute for that specific object. However, car2 is a distinct instance with no 'wheels' key in its own namespace, so it cannot see car1's shadowing entry. Python's lookup for car2 continues past the instance and finds the class attribute, which is still 4, making 3 an incorrect answer.
- ✗
AttributeError
Why it's wrong here
AttributeError would only be raised if neither the instance's __dict__ nor any class in the MRO contained a 'wheels' attribute. Here the Car class explicitly defines wheels = 4 at class creation time, so that attribute exists and is accessible to every instance that does not shadow it. Since car2 does not shadow it, accessing car2.wheels resolves successfully to 4—no missing-attribute exception can occur.
- ✗
None
Why it's wrong here
None is not a fallback in Python's attribute lookup mechanism; if an attribute is not found, the interpreter raises AttributeError rather than silently returning None. Car2 has no instance attribute named wheels, so the lookup proceeds to the class and retrieves the class attribute's value, which is the integer 4. The only way this option would even be plausible is if Car explicitly set wheels = None, but the class definition sets it to 4.
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.