Bird
0
0

Which statement about class attributes is true?

hard📝 Conceptual Q10 of 15
Python - Classes and Object Lifecycle
Which statement about class attributes is true?
AClass attributes cannot be accessed from instances
BClass attributes are stored in each instance's __dict__
CChanging a class attribute affects all instances unless overridden
DInstance attributes override class attributes only if they have the same value
Step-by-Step Solution
Solution:
  1. Step 1: Understand storage of attributes

    Class attributes are stored in the class's __dict__, not in instance __dict__ unless overridden.
  2. Step 2: Understand attribute overriding

    Instance attributes override class attributes regardless of value, and changing class attribute affects all instances without override.
  3. Final Answer:

    Changing a class attribute affects all instances unless overridden -> Option C
  4. Quick Check:

    Class attribute change affects instances without instance override [OK]
Quick Trick: Class attribute changes reflect in instances without instance override [OK]
Common Mistakes:
  • Thinking class attributes are in instance __dict__
  • Believing instance override depends on value
  • Assuming instances cannot access class attributes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes