Formal and Actual Parameters

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:

  1. Will the instance variable balance hold its value permanently?
    • Yes — balance is part of the state of the object and holds its value as long as the object exists.
  2. Will the parameter amount hold its value permanently?
    • No — amount is used only to pass in a value into the method. It is not permanent.

Formal and Actual Parameters

An identifier is a name used for a class, a variable, a method, or a parameter. The following definitions are useful:

  • formal parameter — the identifier used in a method to stand for the value that is passed into the method by a caller.
    • For example, amount is a formal parameter of processDeposit
  • actual parameter — the actual value that is passed into the method by a caller.
    • For example, the 200 used when processDeposit is called is an actual parameter.

When a method is called, the formal parameter is temporarily "bound" to the actual parameter. The method uses the formal parameter to stand for the actual value that the caller wants to be used.

For example, here the processDeposit method uses the formal parameter amount to stand for the actual value used in the procedure call:

balance = balance + amount ; 

Note: formal parameters are bound to an actual value only as long as their method is active. When a method returns to its caller, the formal parameters no longer contain any values. They cannot be used to store the state of an object.

QUESTION 3:

What is used to store the state of an object?