Java Reference
In-Depth Information
42
Figure 8
Calling the replace Method
When a method is defined in a class, the definition specifies the types of the explicit
parameters and the return value. For example, the String class defines the length
method as
public int length()
That is, there are no explicit parameters, and the return value has the type int . (For
now, all the methods that we consider will be Ȓpublicȓ methodsȌsee Chapter 10 for
more restricted methods.)
The type of the implicit parameter is the class that defines the methodȌ String in
our case. It is not mentioned in the method definitionȌhence the term Ȓimplicitȓ.
The replace method is defined as
public String replace(String target, String
replacement)
To call the replace method, you supply two explicit parameters, target and
replacement , which both have type String . The returned value is another string.
When a method returns no value, the return type is declared with the reserved word
void . For example, the PrintStream class defines the println method as
public void println(String output)
Search WWH ::




Custom Search