← Quiz: What Is OOP: all 10 questions
Quiz: What Is OOP · Question 2 of 10
What does this print? (code)
What does this print?
class Counter:
def __init__(self):
self.n = 0
def tick(self):
self.n += 1
a, b = Counter(), Counter()
a.tick(); a.tick(); b.tick()
print(a.n, b.n)
- A.3 3
- B.2 1
- C.1 1
- D.0 0
Answer & explanation
Correct answer: 2 1
Each object has its own state: a ticked twice, b once.
Can you get the rest right without peeking?
Take the timed Quiz: What Is OOP quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →