Java Reference
In-Depth Information
ACTUAL PARAMETER LIST
An actual parameter list has the following syntax:
expression or variable, expression or variable, ...
As with value-returning methods, in a method call the number of actual parameters, together
with their data types, must match the formal parameters in the order given. Actual and formal
parameters have a one-to-one correspondence. A method call causes the body of the called
method to execute. Two examples of void methods with parameters follow.
EXAMPLE 7-5
Consider the following method heading:
public static void
funexp(
int
a,
double
b,
char
c, String name)
The method
funexp
has four formal parameters: (1)
a
, a parameter of type
int
;
, (2)
b
,a
parameter of type
double
;
, (3)
c
, a parameter of type
char
, and (4)
name
, a parameter of
type
String
.
EXAMPLE 7-6
Consider the following method heading:
public static void
expfun(
int
one,
char
two, String three,
double
four)
The method
expfun
has four formal parameters: (1)
one
, a parameter of type
int
;
, (2)
two
, a parameter of type
char
;
, (3)
three
, a parameter of type
String
, and (4)
four
,a
parameter of type
double
.
Parameters provide a communication link between the calling method (such as
main
)andthe
called method. They enable methods to manipulate different data each time they are called.
EXAMPLE 7-7
Suppose that you want to print a pattern (a triangle of stars) similar to the following:
*
* *
* * *
* * * *
The first line has one star with some blanks before the star, the second line has two stars,
some blanks before the stars, and a blank between the stars, and so on. Let's write the
Search WWH ::
Custom Search