java基础

方法重载

方法名称相同,但参数类型和参数的个数不同。

通过传递参数的个数及类型的不同可以完成不同功能的方法调用。

`` public static void main(String[] args) {
int one = add(10,20);
int two = add(10,20,30);
float three = add(10.3f+13.3f);

}

public static int add(int x, int y){

    int temp = 0;
     temp = x+y;
    return temp;

}

public static int add(int x,int y,int z){

    int temp;
    temp = x+y+z;
    return temp;

}

public static float add(float x,float y){

    float temp = 0;
    temp = x+y;
    return temp;

}
posted @ 2018-03-01 14:03  刘莹小西瓜  阅读(122)  评论(0编辑  收藏  举报