Python Programming - Encapsulation - Discussion

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

    def withdraw(self, amount):
        if amount <= self._balance:
            self._balance -= amount
            return amount
        else:
            return "Insufficient funds"
What encapsulation concept is demonstrated in this code?
Public access specifier
Private access specifier
Protected access specifier
Global variable
Answer: Option
Explanation:
The single underscore prefix before 'balance' indicates that it is a public variable, allowing access outside the class.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.