1.名字可以重复,但需要参数类型不同(一个是double 一个是int)
方法重载max(2,90) max(50,60)
package method;
public class demo_02 {
public static void main(String[] args) {
//方法重载max(2,90) max(50,60) 名字可以重复,但需要参数类型不同
int max= max(2,90);
System.out.println(max);
double max1 =max(50,60);
System.out.println(max1);
}
public static double max(double num1,double num2){
double result =0;
if (num1==num2){
System.out.println("两数相等");
return 0;
}
if (num1>num2){
result=num1;
}else {
result=num2;
}
return result;
}
public static int max(int num1,int num2){
int result =0;
if (num1==num2){
System.out.println("两数相等");
return 0;
}
if (num1>num2){
result=num1;
}else {
result=num2;
}
return result;
}
}
结果:
90
60.0