Usage of return in Java (two kinds) _java

Source: Internet
Author: User

The return statement in Java is always closely related to the method, which is always used in the method, has two functions, one is the value that returns the specified type of the method (this value is always determined), and one is the execution of the End method (only a return statement).

In the various articles in the return statement, most of the returns statements are only used in methods that have returned values (not void return values). There is little or no introduction to the use of return statements in the Vodi value method.

The return statement is used in a method that is not a void return value type, not only for returning the base type, but also for returning (including the user-defined Class) object.

One: The return statement is always used in the method and has two effects:

One is the value of the specified type of the return method (this value is always determined),

One is the execution of the End method (just a return statement).

Two:

Instance 1--Returns a string

private string gets () {
string s = ' qw789 ';
return s;
}

Instance 2--End Program

private void gets (String s) {
if (s = = null) {return
;
}
System.out.println ("haha");
}

The above two kinds of examples for you to introduce the use of return in Java, I hope to help you.

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.