ProgrammingModerateProduct-company MCQ pattern

What is printed?

What is printed?
class A:
    count = 0
    def __init__(self):
        A.count += 1
        self.count = 10
a = A(); b = A()
b.count += 5
print(A.count, a.count, b.count)
  1. A. 12 10 15
  2. B. 2 2 7
  3. C. 2 10 15
  4. D. 2 10 10

Correct answer: C. 2 10 15

A.count is the class attribute, incremented once per object (2). self.count = 10 creates an instance attribute that shadows it on each object; b.count += 5 changes only b's own attribute.

More Python Programming questions

Exams that ask this topic