1. Correctly differentiate functions and methods:
The object-oriented language is called the method, the process-oriented language is called the function, the meaning of the two is the same, but the name is different. Java is an object-oriented language, so use the method.
2. Definition of the method:
It's a code snippet with a name.
3. Purpose of the method:
is for the reuse of code.
The same type of operation does not allow duplicate write code. If you write a lot of similar code in the code, there's a problem with the program you're writing.
4. Composition of the method:
The method modifier list method returns a value type method name (parameter 1, parameter 2, ...). ){
Execute the statement;
}
Comments:
1 The list of method modifiers is optional: permission-controlled: public/protected/private/static, the method modifier list can be omitted.
2 return value type: 11 Any one of the types in the data type
3 no return value type is used with the void,void default to bring return, so return write does not write the same.
4 method name as long as it is a valid identifier
5 method parameter list, multiple comma separated, formal parameter also to indicate data type;
Formal parameter: Refers to those parameters at the function/method definition; Syntax: Data type variable name, data type variable name, ....
Argument: Refers to the parameter passed in at the function call.
6 inside the method body, if there is a return value (type), use the return statement, Syntax: return value; And return is the End function.
5. Invocation of the method:
A. Invocation of a static method: class name. static method name (parameter); assigns the return value to a variable.
B. Invocation of a member method: you first need to assign a new object to the variable and then use the object name. Method name (parameter); Assigns the return value to a variable.
Note: If you call a method in this class in a class, you do not need an object name/class name.
A preliminary approach to understanding Java