|
Is the name of a method inside or outside the glass box? A good answer might be:Outside---so it can be "seen" and used by . | |
Assigning to a Parameter
Within the body of a method, a parameter can be used just like any variable. It can be used in arithmetic expressions, in assignment statements, and so on. However, changes made to the parameter do not have any effect outside the method body. A parameter is a "local copy" of whatever value the caller passed into the method. Any changes made to it affect only this local copy. For example: The formal parameter amount is the name used by processCheck() for the value 5000 that it has been given by the caller. The method can change the value held in amount, but this has no effect on the caller's variables.This subject will be further discussed in a future chapter. For now, regard a parameter as a "one-way message" that the caller uses to send values to the method. | |
QUESTION 8:Say that the main() method in the example did this: Is this OK? What would the statementact.processCheck( 7000 ); // call processCheck with the value 7000 in the method do? Click Here after you have answered the questionamount = 0 ; // change the local copy in "amount" |