码迷,mamicode.com
首页 > 编程语言 > 详细

java基础

时间:2018-03-01 17:31:41      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:string   3.3   ret   功能   one   logs   java   完成   turn   

方法重载

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

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

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

}

java基础

标签:string   3.3   ret   功能   one   logs   java   完成   turn   

原文地址:https://www.cnblogs.com/coderly2017/p/8488123.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!