Parameter passing me..

Download Report

Transcript Parameter passing me..

Parameter passing mechanism:
pass-by-value
Introduction
• In the last webpage, we discussed how to pass information
to a method
• I have kept it (deliberately) simple by using constant values
as parameters:
r = ToolBox.min( 1.0, 4.0 );
• In this webpage, we will discuss how to pass information
stored in variables to a method.
Specifically, we will study the pass-by-value mechanism
Example: passing information stored in
variables
• Consider the following program:
Example: passing information stored in
variables (cont.)
• Question to ponder:
• How can we pass (give) the information stored
inside the variables x and y to the method
ToolBox.min
There are quite a few ways to allow (enable) you to
accomplish this "passing"
The possible answers ranges from simple to pretty weird
Parameter passing mechanisms
• Definition: