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 }