java,方法重载小问题
论文问答
1
//显示/int result =sum(a:10,b:20);报错
import java.util.*;
public class HelloWorld {
public static void main(String[] args) {
//System.out.println("Hello world!");
int result =sum(a:10,b:20);
System.out.println(result);
}
public static int sum(int a,int b){
return a+b;
}
public static double sum(double a, double b){
return a+b;
}
public static int sum(int a,int b,int c){
return a+b+c;
}
}
-
不需要 a:和b:
public class HelloWorld { public static void main(String[] args) { //System.out.println("Hello world!"); int result = sum(10, 20); System.out.println(result); } public static int sum(int a, int b) { return a + b; } public static double sum(double a, double b) { return a + b; } public static int sum(int a, int b, int c) { return a + b + c; } }
发表回复