动手动脑的问题以及课后实验性的问题2

请看以下代码,你发现了有什么特殊之处吗?

 1 // MethodOverload.java
 2 // Using overloaded methods
 3 
 4 public class DDD {
 5 
 6     public static void main(String[] args) {
 7         System.out.println("The square of integer 7 is " + square(7));
 8         System.out.println("\nThe square of double 7.5 is " + square(7.5));
 9     }
10 
11     public static int square(int x) {
12         return x * x;
13     }
14 
15     public static double square(double y) {
16         return y * y;
17     }
18 }

运行结果

 发现重载函数参数类型不同返回的值也不同。

猜你喜欢

转载自www.cnblogs.com/125418a/p/11590251.html