It can achieve separate functions;
Which must be defined in the class;
It will only be called to perform;
It can be reused;
After losing methods in object references;
How to define a function, and by means of reflected:
① a clear result of the calculation function. Explicit return type;
② clear in the course of implementing the function is unknown whether there is content involved in computing, to determine the list of parameters;
Eg:
package reviewDemo;
/**
* The value of player's are 2, 3 or other value, the method returns "Ming dynasty", "two out", "Xiao Ming," "I do not have this baby."
*/
public class Demo2 {
public static void main(String[] args) {
int player = 5;
. The System OUT .println ( "returned result is:" + Show (Player));
}
public static String show(int p){
switch (p) {
case 1:
return "Ming dynasty";
case 2:
return "二明";
case 3:
return "小明";
default:
return "I do not have this baby!";
}
}
}