返回值不同的不能说明是重载,编译时会报函数已定义错误。如下代码:
- public class OverloadTest
- {
- public static void main()
- {
- System.out.println("返回值类型为int --- "+add(23,32));
- System.out.println("返回值类型为double --- "+add(23,32));
- }
- public static int add(int numA,int numB)//返回值类型为int
- {
- return numA + numB;
- }
- public static double add(int numA,int numB)//返回值类型为double
- {
- return numA + numB;
- }
- }
复制代码
|