阿摩線上測驗 登入

試題詳解

試卷:104年 - SCJP 151-200#99330 | 科目:OJCP(SCJP)

試卷資訊

試卷名稱:104年 - SCJP 151-200#99330

年份:104年

科目:OJCP(SCJP)

185. Given:
 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 statement is true?
(A) The equals method does NOT properly override the Object.equals method.
(B) Compilation fails because the private attribute p.name cannot be accessed in line 5.
(C) To work correctly with hash-based data structures, this class must also implement the hashCode method.
(D) When adding Person objects to a java.util.Set collection, the equals method in line 4 will prevent duplicates.
正確答案:登入後查看