Java Reference
In-Depth Information
Here is the output produced by the program:
In the program,
isEven( )
is called three times, and each time a different value is passed.
Let's look at this process closely. First, notice how
isEven( )
is called. The argument is spe-
cified between the parentheses. When
isEven( )
is called the first time, it is passed the value
10. Thus, when
isEven( )
begins executing, the parameter
x
receives the value 10. In the
second call, 9 is the argument, and
x
, then, has the value 9. In the third call, the argument
is 8, which is the value that
x
receives. The point is that the value passed as an argument
when
isEven( )
is called is the value received by its parameter,
x
.
A method can have more than one parameter. Simply declare each parameter, separating
one from the next with a comma. For example, the
Factor
class defines a method called
isFactor( )
that determines whether the first parameter is a factor of the second.