与等式方法相关的 Java 代码
我正在练习考试,发现了一个我不明白的样题。
对于以下代码,请查找输出内容:
public class Test {
private static int count = 0;
public boolean equals(Test testje) {
System.out.println("count = " + count);
return false;
}
public static void main(String [] args) {
Object t1 = new Test();
Object t2 = new Test();
Test t3 = new Test();
Object o1 = new Object();
++count; t1.equals(t2);
++count; t1.equals(t3);
++count; t3.equals(o1);
++count; t3.equals(t3);
++count; t3.equals(t2);
}
}
这段代码的输出是,但我不明白为什么。任何人都可以帮我吗?count = 4