This is what I am going to ask online ~~ Sharing a little bit ~~
1. Function of return Statement: a. return a value, which can be of any type. B. Return the program to the operating system (that is, terminate the program)
2. For a function in java, a return statement can be included regardless of whether the return value type exists.
However, the difference is that the return statement can return a value (depending on the type of return Value of the function ).
A. If a function has a return value type (that is, the return value type is not void), a return statement must be included to return the corresponding type value.
B. If the function does not return values (that is, the return value type is void), return statements in the function (if there is a return statement !) You cannot add any variables. (In this case, the function can also have no return statement, but if so, return can only be used as a return operation system .)
For example:
1. return values
Public int getAge ()
{
Return age; // return the age value of the int type variable.
}
2. No return value // The function does not contain a return statement.
Public void putAge ()
{
System. out. println (age );
}
3. No return value is returned to the operating system // function, but with a return statement
Public void put (int ){
If (a> 0)
Return; // The return statement does not contain the return value. It is used to exit the running of the program.
Else
System. out. println ("fasfsa ");
}