无名商城论坛

搜索
查看: 278|回复: 0

[其他技术] 【分享】【记录】寒假学Java(14—2)

[复制链接]

1万

主题

1万

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
32464
发表于 2022-5-8 18:25:37 | 显示全部楼层 |阅读模式
//重载小练习//判断两个数是否相等
//byte short int long

参数列表不同
代码
public class TestfunctionOverload {
    public static void main(String[] args) {
        System.out.println(isSame((byte) 10,(byte) 20));
//强制类型转换
        System.out.println(isSame((short)10,(short)20));
        System.out.println(isSame(10,20));
        System.out.println(isSame((long) 10,(long) 20));
    }
    public static boolean isSame(byte a,byte b){
        return a==b;
    }
    public static boolean isSame(short a,short b){//参数列表不同
        return a==b;
    }
    public static boolean isSame(int a,int b){
        return a==b;
    }
    public static boolean isSame(long a,long b){
        return a==b;
    }
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表