Java动手又动脑

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

public class MethodOverLoad { 
    public static void main(String[] args) {

  System.out.println("The square of integer 7 is " + square(7));         

  System.out.println(" The square of double 7.5 is " + square(7.5));     

  }

  public static int square(int x)

{         

  return x * x;    

  }
  

public static double square(double y)

{         

return y * y;

     }

}

上诉代码由于方法的参数类型不同(一个为 int,一个为 double ),使同名的函数被调用时有所区分;满足以下条件的两个或多个方法构成“重载”关系: 方法名相同, 参数类型不同,参数个数不同,或参数类型的顺序不同;但方法的返回值不作为方法重载的判断条件。

原文地址:https://www.cnblogs.com/y862621115/p/7661200.html