Scjp题目Question 174Click the Exhibit button.1.import java.util.*; 2.class KeyMaster { 3.public int i; 4.public KeyMaster(int i) { this.i = i; } 5.public boolean equals(Object o) { return i == ((KeyMaster)o).i; } 6.public int hashCode() { return i;

来源:学生作业帮助网 编辑:作业帮 时间:2024/07/13 12:03:04
Scjp题目Question 174Click the Exhibit button.1.import java.util.*; 2.class KeyMaster { 3.public int i; 4.public KeyMaster(int i) { this.i = i; } 5.public boolean equals(Object o) { return i == ((KeyMaster)o).i; } 6.public int hashCode() { return i;
xk@{ܚk+:fTd/XMtN(8Eqe2s%Ik3Ehy^҂W,WjVo㵀0N]M+u-n[ԤuHsPM Nmxf X1c Y_9΁CH`E`4]&Vm]5k۟ |yiCˌc*t 3V+DjR3?!![E""#4#&N͌I6\mnV\4]Z L}޸ 2׳L8`YDE$ǣp`]@ @A`A\j cׅmwGu$OOWȕ6Izc[ 7!ԡnab2M6_E72P2d D^2=%ȋP)5ˉ _Vx(>9nmTg Xڢޏv^=f=};jʚH-= \ os|_v//7 aO'+6

Scjp题目Question 174Click the Exhibit button.1.import java.util.*; 2.class KeyMaster { 3.public int i; 4.public KeyMaster(int i) { this.i = i; } 5.public boolean equals(Object o) { return i == ((KeyMaster)o).i; } 6.public int hashCode() { return i;
Scjp题目
Question 174
Click the Exhibit button.
1.import java.util.*;
2.class KeyMaster {
3.public int i;
4.public KeyMaster(int i) { this.i = i; }
5.public boolean equals(Object o) { return i == ((KeyMaster)o).i; }
6.public int hashCode() { return i; }
7.}
8.public class MapIt {
9.public static void main(String[] args) {
10.Set set = new HashSet();
11.KeyMaster k1 = new KeyMaster(1);
12.KeyMaster k2 = new KeyMaster(2);
13.set.add(k1); set.add(k1);
14.set.add(k2); set.add(k2);
15.System.out.print(set.size() + °:±
16.k2.i = 1;
17.System.out.print(set.size() + °:±
18.set.remove(k1);
19.System.out.print(set.size() + °:±
20.set.remove(k2);
21.System.out.print(set.size());
22.}
23.}
What is the result?
A.4:4:2:2
B.4:4:3:2
C.2:2:1:0
D.2:2:0:0
E.2:1:0:0
F.2:2:1:1
G.4:3:2:1
Answer:F
为什么不选c呢?

Scjp题目Question 174Click the Exhibit button.1.import java.util.*; 2.class KeyMaster { 3.public int i; 4.public KeyMaster(int i) { this.i = i; } 5.public boolean equals(Object o) { return i == ((KeyMaster)o).i; } 6.public int hashCode() { return i;
因为现在的k2和加入进去的k2不是同一个,所以你根本无法去掉原来那个.