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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通