Compilation fails because the hashCode method is not overridden.
A HashSet could contain multiple Person objects with the same name.
All Person objects will have the same hash code because the hashCode method is not overridden.
If a HashSet contains more than one Person object with name="Fred", then removing another Person,also with name="Fred", will remove them all.
第1题:
public class Person { private String name, comment; private int age; public Person(String n, int a, String c) { name = n; age = a; comment = c; } public boolean equals(Object o) { if(! (o instanceof Person)) return false; Person p = (Person)o; return age == p.age && name.equals(p.name); } } What is the appropriate definition of the hashCode method in class Person?()
第2题:
public class Person { private name; public Person(String name) { this.name = name; } public int hashCode() { return 420; } } Which is true?()
第3题:
A.A finalizer may NOT be invoked explicitly.
B.The finalize method declared in class Object takes no action.
C.super.finalize()is called implicitly by any over riding finalize method.
D.The finalize method for a given objec twill be called no more than once by the garbage collector.
E.The order in which finalize will be called on two objects is based on the order in which the two objects became finalizable.
第4题:
Which of the following statements are true?()
第5题:
Given: String value = getServletContext().getInitParameter("foo"); in an HttpServlet and a web applicationdeployment descriptor that contains:
第6题:
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 is true?()
第7题:
11. public static void main(String[] args) { 12. Object obj = new Object() { 13. public int hashCode() { 14. returns 42; 15. } 16. }; 17. System.out.println(obj.hashCode()); 18. } What is the result? ()
第8题:
A.True
B.Not true
C.An exception is thrown at runtime.
D.Compilation fails because of an error at line 12.
E.Compilation fails because of an error at line 19.
第9题:
Which two statements are true regarding the return values of property written hashCode and equals methods from two instances of the same class?()
第10题:
public class Person { private name; public Person(String name) { this.name = name; } public boolean equals(Object o) { if( !o instanceof Person ) return false; Person p = (Person) o; return p.name.equals(this.name); } } Which is true?()