Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 40)
40.
Consider the following Python code:
class BankAccount:
    def __init__(self, balance):
        self.__balance = balance

    def get_balance(self):
        return self.__balance

    def deposit(self, amount):
        if amount > 0:
            self.__balance += amount
What is the encapsulation concept demonstrated in this code?
Public access specifier
Private access specifier
Protected access specifier
Global variable
Answer: Option
Explanation:
The double underscore prefix in the variable __balance indicates that it is a private variable, demonstrating the encapsulation concept of private access.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.