Implementing the Method

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

int getBalance()

Other names for the method would also work, of course.

Implementing the Method

The method returns the current balance, which is an int so the return type is int. The method does not need any input data, so its parameter list is empty. The two parentheses () are needed, even though there is nothing inside of them. So far, the class looks like this:

class CheckingAccount
{
  // instance variables
  String accountNumber;
  String accountHolder;
  int    balance;

  //constructors
  . . . .

  // methods
  int getBalance()
  {
     return  ;
  }

}

All getBalance() needs is a statement that returns the balance of the checking account.

QUESTION 12:

Complete the method by filling in the blank.