Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 56)
56.
What is the primary purpose of encapsulating the 'balance' variable in the following Python class?
class BankAccount:
    def __init__(self, balance):
        self._balance = balance

    def get_balance(self):
        return self._balance
To create a new instance of the class
To make the 'balance' variable public
To provide controlled access to the 'balance' variable
To allow unrestricted access to the 'balance' variable
Answer: Option
Explanation:
Encapsulation is used to provide controlled access to variables, and in this case, it is applied to the 'balance' variable.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.