black

SCJP程序员认证考试

登录

单项选择题

import java.util.*; 
class KeyMaster { 
public int i; 
public KeyMaster(int i) { this.i = i; } 
public boolean equals(Object o) { return i == ((KeyMaster)o).i; } 
public int hashCode() { return i; } 
} 
public class MapIt { 
public static void main(String[] args) { 
Set set = new HashSet(); 
KeyMaster k1 = new KeyMaster(1); 
KeyMaster k2 = new KeyMaster(2); 
set.add(k1); set.add(k1); 
set.add(k2); set.add(k2); 
System.out.print(set.size() + “:”); 
k2.i = 1; 
System.out.print(set.size() + “:”); 
set.remove(k1); 
System.out.print(set.size() + “:”); 
set.remove(k2); 
System.out.print(set.size());
} 
} 
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

相关考题

多项选择题 WhichtwostatementsaretrueaboutthehashCodemethod?()

单项选择题 1. public class Person {  2. private String name;  3. public Person(String name) { this.name = name; }  4. public boolean equals(Person p) {  5. return p.name.equals(this.name);  6. }  7. }  Which is true?()

单项选择题 public class Person {  private name;  public Person(String name) {  this.name = name;  }  public boolean equals(Object o) {  if( !o instanceof Person ) return false;  Person p = (Person) o;  return p.name.equals(this.name);  }  }  Which is true?()

All Rights Reserved 版权所有©考试题库网(kstiku.com)

备案号:湘ICP备14005140号-3

经营许可证号:湘B2-20140064