JIANGzihao0222

导航

 

package Test2;

public class Test2 {

public static int square(int x)
{
return x*x;
}
public static double square(double y)
{
return y*y;
}
public static void main(String[]args)
{
System.out.println("The square of integer 7 is "+ square(7));
System.out.println("\nThe square of integer 7.5 is "+ square(7.5));
}
}

重载:

函数名相同,返回值不同,参数个数相同,参数类型不同,调用会根据情况具体调用。

满足以下条件的两个或多个方法构成“重载”关系:

(1)方法名相同; (2)参数类型不同,参数个数不同,或者是参数类型的顺序不同。 注意:方法的返回值不作为方法重载的判断条件。

posted on 2022-09-20 11:24  实名吓我一跳  阅读(25)  评论(0)    收藏  举报