Java方法重载
class MathUtils {
public static int add(int a, int b) {
return a + b;
}
public static double add(double a, double b) {
return a + b;
}
public static int add(int a, int b, int c) {
return a + b + c;
}
}
public class Main {
public static void main(String[] args) {
int sum1 = MathUtils.add(2, 3);
System.out.println("Sum1: " + sum1); // 输出:Sum1: 5
double sum2 = MathUtils.add(2.5, 3.7);
System.out.println("Sum2: " + sum2); // 输出:Sum2: 6.2
int sum3 = MathUtils.add(2, 3, 4);
System.out.println("Sum3: " + sum3); // 输出:Sum3: 9
}
}
标签:MathUtils,10,int,double,add,static,打卡,public
From: https://www.cnblogs.com/wlxdaydayup/p/17542097.html