A method can compute and return a value to its calling
program. The
return
statement specifies an expression whose type must match the return
type specified for the method and whose value is computed and returned
to the calling program.
Pattern:
return expression;
where:
As an example, consider the return statement in
computeDistance()
, which computes and returns the Euclidean distance between the x-y
coordinates received from the calling program. The control flow (see
the arcs labelled 1-5) proceeds as follows:
return
statement, which passes
control back to the calling program,
diameter
and proceeds on
through the calling program.