Java Reference
In-Depth Information
abstract
. More information about these modifiers is provided in
Chapter 8. Meanwhile, we will use the modifiers
public
and/or
static
, as used in the method
main
.
returnType
is the type of value that the method returns. This type is
also called the type of the value-returning method.
methodName
is a Java identifier, giving a name to the method.
Statements enclosed between braces form the body of the method.
In Java,
public
,
protected
,
private
,
static
, and
abstract
are reserved words.
Abstract methods are covered in Chapter 10. Chapter 8 describes, in detail, the meaning
of the modifiers
public
,
private
, and
static
.
SYNTAX: FORMAL PARAMETER LIST
The syntax of a formal parameter list is:
dataType identifier, dataType identifier,....
METHOD CALL
The syntax to call a value-returning method is:
methodName(actual parameter list)
SYNTAX: ACTUAL PARAMETER LIST
The syntax of an actual parameter list is:
expression or variable, expression or variable, ...
Thus, to call a value-returning method, you use its name, with the actual parameters (if any)
in parentheses.
A method's formal parameter list can be empty, but the parentheses are still needed. If the
formal parameter list is empty, the method heading of the value-returning method takes
the following form:
modifier(s) returnType methodName()
If the formal parameter list is empty, in a method call, the actual parameter list is also
empty. In the case of an empty formal parameter list, in a method call, the empty
Search WWH ::
Custom Search