多选题Which two statements are true about the hashCode method?()AThe hashCode method for a given class can be used to test for object equality and object inequality for that class.BThe hashCode method is used by the java.util.SortedSet collection class to or

题目
多选题
Which two statements are true about the hashCode method?()
A

The hashCode method for a given class can be used to test for object equality and object inequality for that class.

B

The hashCode method is used by the java.util.SortedSet collection class to order the elements within that set.

C

The hashCode method for a given class can be used to test for object inequality, but NOT objecte quality, for that class.

D

The only important characteristic of the values returned by a hashCode method is that the distribution of values must follow a Gaussian distribution.

E

The hashCode method is used by the java.util.HashSet collection class to group the elements within that set into hash buckets for swift retrieval.

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

Which two statements are true about the hashCode method?()

  • A、 The hashCode method for a given class can be used to test for object equality and object inequality for that class.
  • B、 The hashCode method is used by the java.util.SortedSet collection class to order theelements within that set.
  • C、 The hashCode method for a given class can be used to test for object inequality, but NOT object equality, for that class.
  • D、 The only important characteristic of the values returned by a hashCode method is that the distribution of values must follow a Gaussian distribution.
  • E、 The hashCode method is used by the java.util.HashSet collection class to group the elements within that set into hash buckets for swift retrieval.

正确答案:C,E

第2题:

Which statements concerning the methods notify() and notifyAll() are true?  

  • A、Instances of class Thread have a method called notify().
  • B、A call to the method notify() will wake the thread that currently owns the monitor of the object.
  • C、The method notify() is synchronized.
  • D、The method notifyAll() is defined in class Thread.
  • E、When there is more than one thread waiting to obtain the monitor of an object, there is no way to be     sure which thread will be notified by the notify() method.

正确答案:A,E

第3题:

Given a class whose instances, when found in a collection of objects, are sorted by using the compareTo()method, which two statements are true?()

A.The class implements java.lang.Comparable.

B.The class implements java.util.Comparator.

C.The interface used to implement sorting allows this class to define only one sort sequence.

D.The interface used to implement sorting allows this class to define many different sort sequences.


参考答案:A, C

第4题:

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?() 

  • 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.

正确答案:B

第5题:

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.

正确答案:A,D

第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?() 

  • 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.

正确答案:A

第7题:

Which two statements are true regarding the return values of property written hashCode and equals methods from two instances of the same class?()

  • A、 If the hashCode values are different, the objects might be equal.
  • B、 If the hashCode values are the same, the object must be equal.
  • C、 If the hashCode values are the same, the objects might be equal.
  • D、 If the hashCode values are different, the objects must be unequal.

正确答案:C,D

第8题:

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?() 

  • A、 return super.hashCode();
  • B、 return name.hashCode() + age * 7;
  • C、 return name.hashCode() + comment.hashCode() /2;
  • D、 return name.hashCode() + comment.hashCode() / 2 - age * 3;

正确答案:B

第9题:

Given a class whose instances, when found in a collection of objects, are sorted by using the compareTo() method, which two statements are true?()

  • A、The class implements java.lang.Comparable.
  • B、The class implements java.util.Comparator.
  • C、The interface used to implement sorting allows this class to define only one sort sequence.
  • D、The interface used to implement sorting allows this class to define many different sort sequences.

正确答案:A,C

第10题:

Which two statements are true about using the isUserInRole method to implement security in a Java EEapplication?()

  • A、It can be invoked only from the doGet or doPost methods.
  • B、It can be used independently of the getRemoteUser method.
  • C、Can return "true" even when its argument is NOT defined as a valid role name in the deployment descriptor.
  • D、Using the isUserInRole method overrides any declarative authentication related to the method in which it is invoked.

正确答案:B,C

更多相关问题