Overloading 方法重载
方法重载()
点击查看【Overloading.java】代码
/**
* @Title: Overloading-方法重载
* @Description: 随便写写,方法重载的概念:1、方法名相同;2方法的参数类型、参数个数不同;3、方法的返回类型可以不同;4、方法的修饰符可以不同;5、main方法也可以被重载。
* @author: TabKey9
* @CreateDate: 2022.3.1
*/
public class Overloading {
public static void main(String[] args) {
System.out.println(sum(10,20));
System.out.println(sum((byte) 10,(byte) 20));
System.out.println(sum((short) 10,(short) 20));
System.out.println(sum( 10L, 20L));
}
public static boolean sum(byte a,byte b){
System.out.println("byte");
return a == b;
}
public static boolean sum(int a,int b){
System.out.println("int");
return a == b;
}
public static boolean sum(short a,short b){
System.out.println("short");
return a == b;
}
public static boolean sum(long a,long b){
System.out.println("long");
return a == b;
}
}
运行
int
false
byte
false
short
false
long
false