JAVA -- return Analysis

Source: Internet
Author: User

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 ");
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.