Java Reference
In-Depth Information
7.
How can you print out the uppercase version of
ÐHello, World!Ñ
?
8.
Is it legal to call
river.println()
? Why or why not?
39
40
2.4 Method Parameters and Return Values
In this section, we will examine how to provide inputs into a method, and how to
obtain the output of the method.
Some methods require inputs that give details about the work that they need to do. For
example, the
println
method has an input: the string that should be printed.
Computer scientists use the technical term parameter for method inputs. We say that
the string
greeting
is a parameter of the method call
A parameter is an input to a method.
System.out.println(
greeting
)
Figure 5
illustrates passing of the parameter to the method.
Technically speaking, the
greeting
parameter is an explicit parameter of the
println
method. The object on which you invoke the method is also considered a
parameter of the method call, called the implicit parameter. For example,
System.out
is the implicit parameter of the method call
The implicit parameter of a method call is the object on which the method is
invoked.
System.out
.println(greeting)
Some methods require multiple explicit parameters, others don't require any explicit
parameters at all. An example of the latter is the
length
method of the
String
class (see
Figure 6
). All the information that the
length
method requires to do its
jobȌnamely, the character sequence of the stringȌis stored in the implicit parameter
object.