Java方法重载

会有一股神秘感。 提交于 2019-11-27 02:33:54
 1 /**
 2  * 测试方法重载
 3  * @author 张涛
 4  *
 5  *方法重载:
 6  *        1.必须在同一个类中
 7  *        2.方法名相同
 8  *        3.形参的个数,顺序,类型不同
 9  *        4.与方法的修饰值返回值无关
10  *
11  */
12 public class TestOverLoad 
13 {
14     public static void main(String[] args)
15     {
16         System.out.println(TestOverLoad.add(3, 5));
17         System.out.println(add(3,5));
18     }
19     public static int add(int a,int b)
20     {
21         int m = a + b;
22         return m;
23     }
24     public static int add(int a,int b,int c)
25     {
26         int m = a + b + c;
27         return m;
28     }
29     public static double add(int a,double b)
30     {
31         double m = a + b;
32         return m;
33     }
34     public static double add(double a,double b)
35     {
36         double m = a + b;
37         return m;
38     }
39     public static double add(double a,int b,double c)
40     {
41         double m = a + b + c;
42         return m;
43     }
44 }

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!