1. Method definition Format and Analysis
(1) Method Overview: A method is a block of code that accomplishes a particular function.
(2) Define the format:
Modifier returns a value type method name (parameter 1, parameter 2, Parameter 3 ...) {
function body;
return value;
}
(3) Modifiers: public, private, abstract, final class.
(4) Return value type: The type used to qualify the return value.
(5) Method name: a name that is used to invoke the method.
(6) Parameter type: The type of data that is passed in when the method is called.
(7) Parameter name: The variable that is used to receive the data passed in when the method is called.
(8) Method body: The code to complete the function.
(9) Return: Ends the method and brings the return value to the caller.
2, the method of writing and calling
(1) Considerations for defining a method: The type of the explicit return value, the explicit number of parameters, and the type of each parameter.
(2) method with return value: general assignment invocation, e.g. int s = SUM (a, b); The call to System.out.println (A, b) can be made by making an output call without meaning.
(3) Void-Modified method: There is no explicit return value and can only be called separately.
(4) Method overloading: In the same class, more than one method of the same name is allowed, as long as the number or type of their arguments is different. Regardless of the type of the return value, look only at the method name and the parameter list. Called when the JVM distinguishes a method with the same name by different argument lists.
3, the method of parameter delivery:
(1) Formal parameters: variables used to receive actual data.
(2) Actual parameters: the variables that are actually involved in the operation.
(3) When the parameter is the basic data type: the change of the formal parameter does not affect the actual parameters.
(4) When the parameter is a reference data type: The change of formal parameters directly affects the actual parameters.
Java Foundation--day05