Guarding the vault: A banking riddle

Report a typo

What access modifier should be used for the 'balance' variable in the BankAccount class to ensure it can only be accessed within the class itself? Fill in the blanks in the code to implement this correctly.

Fill in the gaps with the relevant elements
  BankAccount {
     double balance;
    public BankAccount(double initialBalance) {
        balance = initialBalance;
    }
    public void deposit(double amount) {
        balance += amount;
    }
    public boolean withdraw(double amount) {
        if (balance >= amount) {
            balance -= amount;
            return true;
        }
        return false;
    }
}

Create a free account to access the full topic