← 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)
- A.999
- B.100
- C.AttributeError
- 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 →