我正在为一场考试做练习,发现有一道样例问题我不理解。
对于以下代码,请找出输出结果:
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
,但我不明白为什么会这样。有人可以帮我吗?