请问sum,sum1,sum2的add分别调用哪个add?这算是函数的重载吧?
- package Temp;
- public class overloadDemo {
- /**
- * @param args
- */
- public static void main(String[] args) {
- int sum = 0;
- int sum1 = 0;
- int sum2 = 0;
-
- sum = add(300,900);
- sum1 = add(3,7);
- sum2 = add(3,177);
- System.out.println("sum:"+sum);
- System.out.println("sum1:"+sum1);
- System.out.println("sum2:"+sum2);
-
- }
- public static int add(byte a, byte b)
- {
- return (a+b);
- }
- public static int add(int a , int b)
- {
- return a+b;
- }
-
- public static int add(int a ,short b)
- {
- return a+b;
- }
- }
复制代码 |
|