200. Given: 11. public class Person{ 12. private String name; 13. public Person(String name){ 14. this.name = name; 15. } 16. public boolean equals(Object o){ 17. if(!(o instanceof Person)) return false; 18. Person p = (Person)o; 19. return p.name.equals(this.name); 20. } 21. } Which statement is true?
(A) Compilation fails because the hashCode method is not overridden.
(B) A HashSet could contain multiple Person objects with the same name.
(C) All Person objects will have the same hash code because the hashCode method is not overridden.
(D) If a HashSet contains more than one Person object with name="Fred", then removing another Person, also with name="Fred", will remove them all.
(A) Compilation fails because the hashCode method is not overridden.
(B) A HashSet could contain multiple Person objects with the same name.
(C) All Person objects will have the same hash code because the hashCode method is not overridden.
(D) If a HashSet contains more than one Person object with name="Fred", then removing another Person, also with name="Fred", will remove them all.
答案:登入後查看
統計: A(1), B(3), C(2), D(3), E(0) #2720755
統計: A(1), B(3), C(2), D(3), E(0) #2720755