Java method definition

Source: Internet
Author: User

The so-called method: is the code used to solve a class of problems of the orderly combination is a functional module.

Format:

Access control modifier return value type method name (parameter list) {

Method body;

}

Access Control modifier: method allows access to the permission range.

Similar Same package Sub-classes of different packages Non-subclasses of different packages
Public Allow Allow Allow Allow
Protected Allow Allow Allow
Default Allow Allow
Private Allow

Return value type: The type of the method return value, if the method does not return any job, the return value type is specified as void, if the method has a return value, you need to specify the type of the return value, and return the value in the method body using the return statement.

Method Name: The name of the method defined, must use a valid identifier

Parameter list: The argument list passed to the method, the arguments can have multiple, multiple parameters are separated by commas, each parameter is composed of parameter type and parameter name, separated by a space

Depending on whether the method has parameters or not, the method can be divided into four classes, with or without a return value:

No parameter no return value method

Non-parametric return value method

No return value method with parameter

Return value method with a parameter

Java method definition

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.