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;
}

}

回复

共1条回复 我来回复
  • 毕业设计工坊
    这个人很懒,什么都没有留下~
    评论

    不需要 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;
        }
    }
    
    0条评论

发表回复

登录后才能评论