The last of the branching statements is the
return statement. The
return statement exits from the current method, and control flow returns to where the method was invoked. The
return statement has two forms: one that returns a value, and one that doesn’t. To return a value, simply put the value (or an expression that calculates the value) after the
The data type of the returned value must match the type of the method’s declared return value. When a method is declared
void, use the form of
return that doesn’t return a value.
The Classes and Objects lesson will cover everything you need to know about writing methods.