选择题内容:已知类Foo的定义如下:
public class Foo {
int value;
Foo(int value) {
this.value = value;
}
public boolean equals(Object obj) {
if (obj instanceof Foo) {
Foo foo = (Foo) obj;
return value == foo.value;
} else {
return false;
}
}
运行下面程序段:
ArrayList list = new ArrayList();
HashSet set = new HashSet();
list.add(new Foo(1));
set.add(new Foo(1));
System.out.println(《插入代码》);
如果控制台输出的结果是true,false,那么《插入代码》处应填入的代码是
A. list.contains(new Foo(1)) + “,”+ set.contains(newFoo(1))
B. set.contains(new Foo(1)) + “,”+ list.contains(newFoo(1))
C. new Foo(1).equals (new Foo(1)) + “,”+ list.contains(newFoo(1))
D. new Foo(1).equals (new Foo(1)) + “,”+ set.contains(newFoo(1))
|