方法重载

 1 package day05;
 2 
 3 public class OverloadDemo {
 4     /*  使用方法重载思想设计比较两个数是否相同的方法,
 5        兼容全整数类型(byte、short、int、long)*/
 6     public static void main(String[] args) {
 7         short a = 10;
 8         short b = 20;
 9         System.out.println(compare(a, b));
10     }
11 
12     public static boolean compare(int a, int b) {
13         return a == b;
14     }
15 
16     public static boolean compare(byte a, byte b) {
17         return a == b;
18     }
19 
20     public static boolean compare(short a, short b) {
21         return a == b;
22     }
23 
24     public static boolean compare(long a, long b) {
25         return a == b;
26     }
27 }

执行结果:

posted @ 2020-12-31 22:31  Eleanor123  阅读(54)  评论(0编辑  收藏  举报