Java Reference
In-Depth Information
Method Declaration
Type
Identifier
Parameters
Throws Clause
Method Body
Modifier
void
Parameters
(
)
Type
Identifier
,
A method is defined by optional modifiers, followed by a return Type, followed
by an Identifier that determines the method name, followed by a list of Parameters,
followed by the Method Body. The return Type indicates the type of value that
will be returned by the method, which may be void . The Method Body is a block
of statements that executes when the method is invoked. The Throws Clause is
optional and indicates the exceptions that may be thrown by this method.
Example:
public void instructions ( int count )
{
System.out.println ("Follow all instructions.");
System.out.println ("Use no more than " + count +
" turns.");
}
main
doThis
helpMe
obj.doThis();
helpMe();
FIGURE 4.7 The flow of control following method invocations
 
Search WWH ::




Custom Search