Use of the non-parametric return value method in Java

Source: Internet
Author: User

If the method does not contain a parameter, but has a return value, we call it a method with no parameter return value.

For example: The following code, which defines a method named Calsum, has no arguments, but the return value is of type int, performs an operation that calculates the sum of two numbers and returns the result

In the Calsum () method, the return value type is type int, so you must return an integer value using return in the method body.

When calling a method with a return value, it is important to note that because the method executes returns a result, the return value is generally received and processed when the return value method is called. Such as:

The result of the operation is: two sum of: 17

"Small traps" that cannot be overlooked:

1. If the return type of the method is void, the return value cannot be used in the method!

2. The return value of a method can have at most one and cannot return multiple values

3, the type of the method return value must be compatible, for example, if the return value type is int, you cannot return a String value

Use of the non-parametric return value method in Java

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.