A “return” statement looks like this:
return;
or
return Expression;
Statement Notes
✓ |
“Return” (with no accompanying expression) is only used in a method that has a return value of void. It gets you out of the method and back to where you were called from. The code below is an example: void resetFields(Customer c) { |
✓ |
A “return Expression” is always used in every method that actually does return a value. It cannot be used in a method whose return value is void. The code below shows an example: int hourOfDay( ) { |
There two other statements that can transfer the flow of control: the “throw” statement that raises an exception, and the “assert” that does sanity-checking of important conditions. These are described in chapter 10 Exceptions.
3.15.226.120