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)