0%
0 / 15 answered

Introduction to Algorithms, Programming, and Compilers Practice Test

15 Questions
Question
1 / 15
Q1

A bank account program models each account as an object with encapsulated state (balance) and methods to change it. The withdraw method checks rules before updating the private field:


public boolean withdraw(double amount) {

  if (amount <= balance) {

    balance -= amount;

    return true;

  }

  return false;

}

Based on the passage, what is the main benefit of calling withdraw instead of changing balance directly?​

Question Navigator