Parameters are Seen by their Own Method, Only

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:

Instance variables are used to store the state of an object. They hold values for as long as the object exists.

Parameters are Seen by their Own Method, Only

The formal parameters of a method can be "seen" only by the statements of their own method. This means that if a method tries to use a parameter of some other method, the compiler will find a syntax error.

Here is the CheckingAccount class again, this time with a new definition of the toString() method

class CheckingAccount
{
  . . . .
  private int balance;

  . . . .
  public void processDeposit( int amount )
  {
    System.out.println( balance + "/t" + amount );
  }

  // modified toString() method
  public String toString()
  {
    return  "Account: " + accountNumber + "/tName: " + accountHolder + 
            "/tBalance: " +  amount  + "/tUse Count: " + useCount;
  }

}

QUESTION 4:

Is this toString() method correct?