[Java study notes] 1-13 overload

Method overloading

definition:

**The names of multiple methods are the same, but the parameter lists are different. **Method names are case sensitive! ! !

benefit:

You only need to remember the only method name to achieve similar functions.

Method overloading is related to the following factors:

1. The number of parameters is different
2. The parameter types are different
3. The order of multiple types of parameters is different

Method overloading has nothing to do with the following factors:

1. It has nothing to do with the name of the parameter
2. It has nothing to do with the return value type of the method

//错误示范,方法重载与方法的返回值无关
public static int sum(int a,int b){
    
    
	return a+b
}
public static double sum(int a,int b){
    
    
	return a+b+0.0
}

3. It has nothing to do with modifiers such as public

[Tips] When
making content changes, select the content shift+F6, and all the same content as the selected content will be changed/changed together

Guess you like

Origin blog.csdn.net/kz_java/article/details/114504383