A Method to Get the Balance

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:

void

A Method to Get the Balance

Here is the class definition, again:

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

  //constructors
  . . . .

  // methods
}

Let us work on a method that will return the current balance. When it is called, it will not alter any data in a checking account object, but will merely return the current balance.

QUESTION 11:

Write the first line of the "current balance" method. The method will not use any parameters. You will have to think of a name for the method.