Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 83)
83.
What is the primary purpose of the following Python class?
class Wallet:
    def __init__(self, owner, __balance):
        self.owner = owner
        self.__balance = __balance

    def get_balance(self):
        return self.__balance
To create a new instance of the class
To provide controlled access to the 'balance' variable
To define a public variable 'balance'
To allow unrestricted access to the 'balance' variable
Answer: Option
Explanation:
The get_balance() method provides controlled and read-only access to the private variable '__balance', demonstrating encapsulation.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.