方法重载
- 方法名必须相同
- 参数必须不同
package com.sund.method;
public class Demo02 {
public static void main(String[] args) {
double test = test(10.0, 10.0);
System.out.println(test);
}
//方法重载:方法名相同,参数类型不同
public static double test(double a,double b){
double sund = 0;
if(a==b){
System.out.println("a==b");
return 0;//终止方法
}
if(a>b){
sund = a;
}else{
sund = b;
}
return sund;
}
public static int test(int a,int b){
int sund = 0;
if(a==b){
System.out.println("a==b");
return 0;//终止方法
}
if(a>b){
sund = a;
}else{
sund = b;
}
return sund;
}
}