阿摩線上測驗 登入

試題詳解

試卷:104年 - SCJP 201-244#99410 | 科目:OJCP(SCJP)

試卷資訊

試卷名稱:104年 - SCJP 201-244#99410

年份:104年

科目:OJCP(SCJP)

210. Given: 
11. public class Person{ 
12. private String name, comment; 
13. private int age;
 14. public Person(String n, int a, String c){ 
15. name = n; age = a; comment = c;
 16. } 
17. public boolean equals(Object o){ 
18. if (!(0 instanceof Person)) return false; 
19. Person p = (Person)o;
 20. return age == p.age && name.equals(p.name); 
21. } 
22. } 
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;
正確答案:登入後查看