java--function (method)

Source: Internet
Author: User

function functions (method)

1. Function call: A function must be declared (defined) before it is called;
① declaration: Must be written to the class (cannot write to main);
② syntax: modifier return type function name (formal parameter list) {
function body (any function, any number of codes)
}
③ can annotate a function (method) (with Javadoc)/** */
The ④ function must execute the function body when it is called.
⑤ Invocation: Function name (argument list)

2. Function:
① Reduce Code duplication
② Reduction of coupling (the relevance of things)
③ Reduction of overall complexity

3. Formal parameter list:
Syntax: Data type parameter name, data type parameter name ...
Parameter: The argument used when the function is defined;
Arguments: Parameters used when a function is called;
When a function is called, the value of the argument is passed to the parameter.

4. List of arguments:
Syntax: expression 1, expression 2 ...

5. function returns: Return
* Write return result in function body: return variable, constant expression
① when the code runs to the return statement, immediately ends the function and returns the result;
② function call: Only care about--function name, parameter, return type, do not care about function body;
③ function Signature: function name, parameter, return type (or three features)
The output of the ④ function call is the caller's thing, not implemented in the function.

6. Participate in the actual parameter:
When the ① function is called, the formal participation argument has an independent memory space;
When ② passes a parameter, the data in the argument memory is copied to the formal parameter.
③ Special Note: In a function, changing the parameter assignment does not affect the argument.

7. Method overloading:
Definition: In a class, multiple functions (methods) with the same name appear, called method overloads. Overload
Feature: function name is the same, parameter list is different (number of parameters or different type)

8. Recursive invocation:
Definition: Calls itself in a function.
Note: To avoid infinite recursion, there must be a termination condition.
9. Examples of functions:

java--function (method)

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.