其他分享
首页 > 其他分享> > 动手动脑

动手动脑

作者:互联网

方法重载

程序代码

package teacher;
public class MethodOverload {

	public static void main(String[] args) 
	{
		System.out.println("The square of integer 7 is " + square(7));
		System.out.println("\nThe 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;
	}
}

  运行结果

The square of integer 7 is 49 The square of double 7.5 is 56.25 结果分析 应为进行了方法重载,所以当传入不同的参数时得到不同的答案。

标签:square,int,double,动脑,动手,static,7.5,public
来源: https://www.cnblogs.com/linmob/p/13772539.html