问题:
A . The equals() method determines if reference values refer to the same object.
B . The == operator determines if the contents and type of two separate objects match.
C . The equals() method returns true only when the contents of two objects match.
D . The class File overrides equals() to return true if the contents and type of two separate objects match.
● 参考解析
严格来说这个问题的答案是不确定的,因为equals()方法是可以被重载的,但是按照java语言的本意来说:如果没有重写(override)新类的equals(),则该方法和 == 操作符一样在两个变量指向同一对象时返回真,但是java推荐的是使用equals()方法来判断两个对象的内容是否一样,就像String类的equals()方法所做的那样:判定两个String对象的内容是否相同,而==操作符返回true的唯一条件是两个变量指向同一对象。从这个意义上来说选择给定的答案。从更严格的意义来说正确答案应该只有D。
相关内容
相关标签