Java Reference
In-Depth Information
value of the variable
number
is passed to the formal parameter
num
. Control now transfers
to the method
primFormalParam
(see Figure 7-4).
main
primFormalParam
num
number
6
6
FIGURE 7-4
The variables
number
and
num
before execution of the statement in Line 13
The statement in Line 12 outputs the value of
num
before changing its value. The
statement in Line 13 changes the value of
num
to
15
(see Figure 7-5).
main
primFormalParam
num
number
6
15
7
FIGURE 7-5
The variables
number
and
num
after execution of the statement in Line 13
The statement in Line 14 outputs the value of
num
. After this statement executes, the
method
primFormalParam
exits and control goes back to the method
main
at Line 8
(see Figure 7-6).
main
number
6
FIGURE 7-6
The variables
number
and
num
after execution of the statement in Line 13
The statement in Line 8 outputs the value of
number
after calling the method
primFormalParam
. As you can see from the output, the value of
number
,asshown
by the output of the statements in Lines 6 and 8, remains the same even though the
value of its corresponding formal parameter
num
was changed within the method
primFormalParam
.
After copying data, a formal parameter of the primitive data type has no connection with
the actual parameter, so a formal parameter of the primitive data type cannot pass any
result back to the calling method. When the method executes, any changes made to the
Search WWH ::
Custom Search