1, return statement function: A, returns a value, this value can be any type. b, return the program to the operating system (that is, terminate the program)
2, in Java for a function, regardless of whether there is a return value type, can be accompanied by returns statements.
The difference, however, is whether the return statement returns a value (depending on the return value type of the function).
A, if the function has a return value type (that is, the return value type is not void), you must have a return statement that returns the corresponding type value.
b, if the function does not have a return value (that is, the return value type is void), returns in the function (if there is a returns statement!). cannot be appended with any variables. (There can be no return statement in the function in this case, but returns can only be used as a function of returning the operating system, if any.) )
For example:
1, have return value
Copy Code code as follows:
public int Getage ()
{
return age; Returns the value of the variable age of type int
}
2, no return value//function without returns statement
Copy Code code as follows:
public void Putage ()
{
System.out.println (age);
}
3, return to the operating system//function has no return value, but with returns statement
Copy Code code as follows:
public void put (int a) {
if (a > 0)
Return Return statement without returning value, the function is to quit the program running
Else
System.out.println ("FASFSA");
}