//方法重载
/* 多个方法在同一个类中
多个方法具有相同的方法名
区别是参数不同或者类型不同或者数量不同
*/
public class test {
public static void main(String[] args) {
System.out.println(compare(1,1));
System.out.println(compare((byte)1,(byte)1));
}
public static boolean compare(byte a,byte b){
System.out.println("byte");
return a==b;
}
public static boolean compare(short a,short b){
System.out.println("short");
return a==b;
}
public static boolean compare(int a,int b){
System.out.println("int");
return a==b;
}
public static boolean compare(long a,long b){
System.out.println("long");
return a==b;
}
}
方法的重载
最新推荐文章于 2023-03-12 19:00:23 发布