Methods, overloading
1. Method: A block of code to complete a specific function
Format: Modifier Returns the value of the method name (argument type parameter name 1, ..., argument type parameter name N) {function body; return value;}.
Note: the "void" method does not require a return value and the method cannot be nested.
1 classfin{2 3 //Main Method4 Public Static voidMain (string[] args) {5 intN=test (3,2);//Call the test method6SYSTEM.OUT.PRINTLN (n);//n=17 }8 9 //test MethodTen Public Static intTestintAintb) { One returnA-b; A } -}
2. Overloading: A method in the same class that allows different parameters of the same name (parameter types or different number of parameters)
Note: Regardless of the return value of the method, just look at the method name and parameter (parameter type, number of arguments) and distinguish the method with the same name by parameter.
1 classfin{2 Public Static voidMain (string[] args) {3 intN=test (3,2,1);4SYSTEM.OUT.PRINTLN (n);//n=65 }6 7 Public Static intTestintAintb) {8 returnA-b;9 }Ten One Public Static intTestintAintBintc) { A returna+b+C; - } -}
Older Dick Silk Self-study note--java 0 basics to rookie--012