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.
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.
举一反三
- 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.
- Which of the following statements are true?() A: The equals() method determines if reference values refer to the same object. B: The == operator determines if the contents and type of two separate objects match. C: The equals() method returns true only when the contents of two objects match. D: The class File overrides equals() to return true if the contents and type of two separate objects match.
- Which statement is true?() A: Compilation succeeds. B: class A does not compile. C: The method declared on line 9 cannot be modified to throw TestException. D: TestA compiles if line 10 is enclosed in try/catch block that catches TestException.
- Which of the following is false? ( ) A: A static method must be used to access private static instance variables. B: A static method can be accessed even when no objects of its class have been instantiated. C: A static method has no this reference. D: A static method can call instance methods directly.
- An object is an instance of a A: program B: class C: method D: data