FunctionDemo2

package java基础知识.小结与练习;

/*
函数的重载
	在同一个类中,允许存在一个以上的同名函数,只要它们的参数个数或者参数类型不同即可。

	简单的记住:
		函数名字相同,参数列表不同。
					  **参数类型
					  **参数个数
*/
class FunctionDemo2 
{
	public static void main(String[] args) 
	{
		//jvm会根据参数自动去找匹配的函数
		System.out.println(sum(10,20));
		System.out.println(sum(10,20,30));
		
		//没写四个参数,所以这个会报错。
		//System.out.println(sum(10,20,30,40));

		System.out.println(sum(12.5,20.2));
	}

	//求两个整数之和
	public static int sum(int a,int b)
	{
		return a + b;
	}

	/*
	需求:求两个浮点数之和

	明确
		1:明确功能 double
		2:明确参数 double a,double b
	*/
	public static double sum(double a,double b)
	{
		return a + b;
	}

	/*
	需求:求三个整数之和

	明确
		1:明确功能 int
		2:明确参数 int a,int b,int c
	*/
	/*
	public static int sum2(int a,int b,int c)
	{
		//return sum(a,b)+c;
		return a + b + c;
	}
	*/
	public static int sum(int a,int b,int c)
	{
		return a + b + c;
	}
}

/*
重载的判断:
下面哪几个函数与这个函数是重载函数
public static void show(int a,int b){}

A:public static int show(int x,int y){}  //不是
B:public static int show(int x,int y,int c){}//是
C:public static void show(float x,int y){} //是
D:public static double show(double x,int y,int z){} //是
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值