C-2 方法重载,比较大小

 1 /*
 2 方法重载
 3 比较两个数据是否相等,参数类型分别为
 4 两个byte、两个short、两个int、两个long
 5 */
 6 
 7 class FunctionTest{
 8     public static void main(String[] args){
 9     
10     //测试
11     byte b1 = 3;
12     byte b2 = 4;
13     System.out.println("byte:"+compare(b1,b2));
14     
15     //测试
16     int i1 = 11;
17     int i2 = 11;
18     System.out.println("int:"+compare(i1,i2));
19     
20     //测试
21     short s1 = 7;
22     short s2 = 9;
23     System.out.println("short:"+compare(s1,s2));
24     
25     //测试
26     long l1 = 7;
27     long l2 = 9;
28     System.out.println("long:"+compare(l1,l2));
29     }
30     
31     //byte类型
32     public static boolean compare(byte a, byte b){
33         System.out.println("byte:");
34         return a == b;
35     }
36     //int类型
37     public static boolean compare(int a, int b){
38         System.out.println("int:");
39         return a == b;
40     }
41     //short类型
42     public static boolean compare(short a, short b){
43         System.out.println("short:");
44         return a == b;
45     }
46     //long类型
47     public static boolean compare(long a, long b){
48         System.out.println("long:");
49         return a == b;
50     }
51 }
原文地址:https://www.cnblogs.com/android-lyz/p/4744593.html