|
What is a parameter of a method? A good answer might be:A parameter is a name used in a method definition for values that will be passed into the method by its callers. | ||
ParametersHere is an example (from the CheckingAccount class of the last two chapters) of a method that uses a parameter. The ellipses (. . . .) show where code not relevant to this discussion has been left out.
The parameter amount is used by a caller send a value to the method. This is usually called passing a value to the method. Here is part of a main() method that uses the parameter to pass a value into the processDeposit() method:
When the statement
is executed, the parameter amount of the object's method will hold the value 200. This value is added to the object's instance variable in the statement
Then the method will be exited and control will return to main(). The state of the object referred to by bobsAccount will have been changed. | ||
QUESTION 2:
|