🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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)
  1. A.3 3
  2. B.2 1
  3. C.1 1
  4. 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 →