black

SCJP程序员认证考试

登录

单项选择题

public class Person { 
private String name, comment; 
private int age; 
public Person(String n, int a, String c) { 
name = n; age = a; comment = c; 
} 
public boolean equals(Object o) { 
if(! (o instanceof Person)) return false; 
Person p = (Person)o; 
return age == p.age && name.equals(p.name); 
} 
} 
What is the appropriate definition of the hashCode method in class Person?() 

A. return super.hashCode();
B. return name.hashCode() + age * 7;
C. return name.hashCode() + comment.hashCode() /2;
D. return name.hashCode() + comment.hashCode() / 2 - age * 3;

相关考题

单项选择题 Aprogrammerhasanalgorithmthatrequiresajava.util.Listthatprovidesanefficientimplementationofadd(0,object),butdoesNOTneedtosupportquickrandomaccess.Whatsupportstheserequirements?()

单项选择题 public class Score implements Comparable {  private int wins, losses;  public Score(int w, int 1) { wins = w; losses = 1; }  public int getWins() { return wins; }  public int getLosses() { return losses; }  public String toString() {  return “<“ + wins + “,“ + losses + “>”; }  // insert code here  }  Which method will complete this class?()

单项选择题 1. import java.util.*;  2. public class TestSet {  3. enum Example { ONE, TWO, THREE }  4. public static void main(String[] args) {  5. Collection coll = new ArrayList();  6. coll.add(Example.THREE);  7. coll.add(Example.THREE);  8. coll.add(Example.THREE);  9. coll.add(Example.TWO);  10. coll.add(Example.TWO);  11. coll.add(Example.ONE);  12. Set set = new HashSet(coll);  13. }  14. }  Which statement is true about the set variable on line 12?()

All Rights Reserved 版权所有©求知题库网库(csqiuzhi.com)

备案号:湘ICP备14005140号-1

经营许可证号:湘B2-20140064