Return is the main language of the regulars, basically have a return statement, then in Java, return what is the special place, let's analyze the next
1, the function of the return statement: A, return 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, whether there is no return value type, you can have a return statement. The difference, however, is whether the return statement can return 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 has no return value (that is, the return value type is void), the return statement in the function, if there is a return statement! ) cannot be added to any of the following variables.
(The function in this case can also have no return statement, but if so, return can only be used as a function of returning the operating system.) )
For example:
1, there is a return value
public int Getage ()
{
return age; Returns the value of the variable age of type int
}
2, no return value//function without return statement
public void Putage ()
{
System.out.println (age);
}
3, return to the operating system//function no return value, but with a return statement
public void put (int a)
{
if (a > 0)
Return The return statement is not returned with a value, the function is to exit the program's Run
Else
System.out.println ("FASFSA");
}
Summary of usage of return statements in Java