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

posted @   TabKey9  阅读(36)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示