java中方法的重载

java中方法的重载

1.概念
在这里插入图片描述
2.方法重载举例

public class PrintStream {
	public static void print(int i) {……}
	public static void print(float f) {……}
	public static void print(String s) {……}
	public static void main(String[] args) {
		print(3);
		print(1.2f);
		print("hello!");
	}
}

使用重载方法,可以为编程带来方便
例如,System.out.println()方法就是典型的重载方法,其内部的声
明形式如下 :
public void println(byte x)
public void println(short x)
public void println(int x)
public void println(long x)
public void println(float x)
public void println(double x)
public void println(char x)
public void println(double x)
public void println()
……

3.方法重载的练习

void show(int a,char b,double c){}构成重载的有:
a) void show(int x,char y,double z){} // no
b) int show(int a,double c,char b){} // yes
c) void show(int a,double c,char b){} // yes
d) boolean show(int c,char b){} // yes
e) void show(double c){} // yes
f) double show(int x,char y,double z){} // no
g) void shows(){double c} // no
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值