class Count{ //方法重载,同一个类中可以有相同的方法 但里面的参数不同 public boolean compare(byte x,byte y){ return x==y; } public boolean compare(short x2,short y2){ return x2==y2; } public boolean compare(int x3,int y3){ return x3==y3; } public boolean compare(long x4,long y4){ return x4==y4; } } public class Method_Demo01 { public static void main(String[] args) { //定义一些数据 用于比较 计算两个值是否相等 byte a=10; byte b=20; short c=10; short d=20; int e=10; int f=10; long g=20; long h=20; Count c1=new Count(); System.out.println(c1.compare(a,b)); System.out.println(c1.compare(c,d)); System.out.println(c1.compare(e,f)); System.out.println(c1.compare(g,h)); } }