🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Encapsulation and Abstraction: all 10 questions

Quiz: Encapsulation and Abstraction · Question 10 of 10

What does this print? (code)

What does this print?

class Account:
    def __init__(self):
        self.__balance = 100

    @property
    def balance(self):
        return self.__balance

a = Account()
a.__balance = 999
print(a.balance)
  1. A.999
  2. B.100
  3. C.AttributeError
  4. D.None
Answer & explanation

Correct answer: 100

The assignment creates a new attribute; the name-mangled real balance stays 100.

Can you get the rest right without peeking?

Take the timed Quiz: Encapsulation and Abstraction quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →