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