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.
举一反三
- Which statement is true?() A: The time to find the value from HashMap with a Person key depends on the size of the map. B: Deleting a Person key from a HashMap will delete all map entries for all keys of type Person. C: Inserting a second Person object into a HashSet will cause the first Person object to be removed as a duplicate. D: The time to determine whether a Person object is contained in a HashSet is constant and does NOT depend on the size of the map.
- Given: 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 hashCodemethod. D: When adding Person objects to a java.util.Set collection,the equals method in line 4 will preventduplicates.
- Overriding a method differs from overloading a method because: ( ) A: Neither of the above. B: Both of the above. C: Overridden methods have the same signature. D: Overloaded methods have the same signature.
- 下列JavaScript定义对象的语句中,()不正确。 A: var person = {}; B: var person = new Object(); C: person =name; D: function person(name,sex){} var personObj = new person();
- 在C#中,下列结构或者类定义正确的是(选一项) A: public struct Person{ string name; int age; public void ShowName(){ Console.WriteLine(name); }} B: public struct Person{ string name; int age; public Person(){ Conssole.WriteLine(name); }} C: public class Person{ string name; int age; public Person(){ Conssole.WriteLine(name); }} D: public class Person{ string name; int age; public Person(string name){ Conssole.WriteLine(name); }}