public boolean equals(Object obj) {
if (!(obj instanceof Demo)) {
return false;
} else {
Demo b = (Demo) obj;
return this.a == b.a;
}
}
public static int getA() {//我给你 加了个getA()方法,获取a的值,因为你的a是private的
return a;
}
}
public class Aquals {
public static void main(String[] args) {
Demo d = new Demo(12);
Demo d1 = new Demo(2);
System.out.println(d.equals(d1));
System.out.println(d.getA());//这里的输出结果,你会发现,结果是一样的,因为静态在本类对象中是共享的
System.out.println(d1.getA());
}
}