BankAccount Balance: Getters & Setters

Report a typo

Consider the following Java class:

public class BankAccount {
  private double balance;

  // Getter
  public double getBalance() {
    return balance;
  }

  // Setter
  public void setBalance(double balance) {
    if (balance >= 0) {
      this.balance = balance;
    }
  }
}
In this example, which of the following statements are true regarding the getters and setters, and their relation to access control?
Select one or more options from the list

Create a free account to access the full topic