单选题Which statement is true?()ACompilation fails because the hashCode method is not overridden.BA HashSet could contain multiple Person objects with the same name.CAll Person objects will have the same hash code because the hashCode  method is not overridd

题目
单选题
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
解析: 暂无解析
更多“单选题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 ov”相关问题
  • 第1题:

    public class Person {  private name;  public Person(String name) {  this.name = name;  }  public int hashCode() {  return 420;  }  }  Which 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 typePerson.
    • C、 Inserting a second Person object into a HashSet will cause the first Person object to beremoved 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.

    正确答案:A

  • 第2题:

    Given: String value = getServletContext().getInitParameter("foo"); in an HttpServlet and a web applicationdeployment descriptor that contains: foo frodo Which two are true?()

    • A、The foo initialization parameter CANNOT be set programmatically.
    • B、Compilation fails because getInitParameter returns type Object.
    • C、The foo initialization parameter is NOT a servlet initialization parameter.
    • D、Compilation fails because ServletContext does NOT have a getInitParameter method.
    • E、The foo parameter must be defined within the  element of the deployment descriptor.

    正确答案:A,C

  • 第3题:

    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

  • 第4题:

    Which statement is true?()

    • A、A class’s finalize() method CANNOT be invoked explicitly.
    • B、super.finalize() is called implicitly by any overriding finalize() method.
    • C、The finalize() method for a given object is called no more than once by the garbage collector.
    • D、The order in which finalize() is called on two objects is based on the order in which the two objects became finalizable.

    正确答案:C

  • 第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
    解析: 严格来说这个问题的答案是不确定的,因为equals()方法是可以被重载的,但是按照java语言的本意来说:如果没有重写(override)新类的equals(),则该方法和 == 操作符一样在两个变量指向同一对象时返回真,但是java推荐的是使用equals()方法来判断两个对象的内容是否一样,就像String类的equals()方法所做的那样:判定两个String对象的内容是否相同,而==操作符返回true的唯一条件是两个变量指向同一对象。从这个意义上来说选择给定的答案。从更严格的意义来说正确答案应该只有D。

  • 第6题:

    单选题
    Click the Exhibit button. Which statement is true about the classes and interfaces in the exhibit?()
    A

    Compilation will succeed for all classes and interfaces.

    B

    Compilation of class C will fail because of an error in line 2.

    C

    Compilation of class C will fail because of an error in line 6.

    D

    Compilation of class AImpl will fail because of an error in line 2.


    正确答案: B
    解析: 暂无解析

  • 第7题:

    单选题
    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.


    正确答案: D
    解析: 暂无解析

  • 第8题:

    单选题
    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? ()
    A

     42

    B

     An exception is thrown at runtime.

    C

     Compilation fails because of an error on line 12.

    D

     Compilation fails because of an error on line 16.

    E

     Compilation fails because of an error on line 17.


    正确答案: B
    解析: 暂无解析

  • 第9题:

    多选题
    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.


    正确答案: E,D
    解析: 暂无解析

  • 第10题:

    单选题
    Because of a logical corruption in your production database, you wanted to perform Tablespace Point in Time Recovery (TSPITR). But before you start the recovery, you queried the TS_PITR_OBJECTS_TO_BE_DROPPED view and realized that there are a large number of objects that would be dropped when you start the recovery by using this method.You want to preserve these objects. Which option must you use to perform TSPITR and preserve the object?()
    A

    Perform Export before TSPITR and Import after TSPITR

    B

    Move objects to another schema that has the same tablespace assigned

    C

    Perform Incomplete Recovery before TSPITR with the Log Sequence Number (LSN)

    D

    Perform Incomplete Recovery before TSPITR with the System Change Number (SCN)


    正确答案: B
    解析: 暂无解析

  • 第11题:

    单选题
    Given: What is the result?()
    A

    B

    B

    The code runs with no output.

    C

    Compilation fails because of an error in line 12.

    D

    Compilation fails because of an error in line 15.

    E

    Compilation fails because of an error in line 18.


    正确答案: A
    解析: 暂无解析

  • 第12题:

    单选题
    You are implementing an ASP.NET application. The application includes a Person class with property Age. You add a page in which you get a list of Person objects and display the objects in a GridView control. You need to add code so that the GridView row is highlighted in red if the age of the person is less than 18. Which GridView event should you handle?()
    A

    RowDataBound

    B

    RowCommand

    C

    RowUpdated

    D

    RowEditing


    正确答案: B
    解析: 暂无解析

  • 第13题:

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

    • A、 42
    • B、 An exception is thrown at runtime.
    • C、 Compilation fails because of an error on line 12.
    • D、 Compilation fails because of an error on line 16.
    • E、 Compilation fails because of an error on line 17.

    正确答案:A

  • 第14题:

    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

  • 第15题:

    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

  • 第16题:

    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.

    正确答案:C,E

  • 第17题:

    多选题
    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
    解析: 暂无解析

  • 第18题:

    单选题
    public class Person {  private name;  public Person(String name) {  this.name = name;  }  public int hashCode() {  return 420;  }  }  Which 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 typePerson.

    C

     Inserting a second Person object into a HashSet will cause the first Person object to beremoved 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.


    正确答案: C
    解析: 暂无解析

  • 第19题:

    单选题
    Which statement is true?()
    A

    A class’s finalize() method CANNOT be invoked explicitly.

    B

    super.finalize() is called implicitly by any overriding finalize() method.

    C

    The finalize() method for a given object is called no more than once by the garbage collector.

    D

    The order in which finalize() is called on two objects is based on the order in which the two objects became finalizable.


    正确答案: C
    解析: 暂无解析

  • 第20题:

    单选题
    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
    解析: 暂无解析

  • 第21题:

    单选题
    Given: What is the result when method testIfA is invoked?()
    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.


    正确答案: B
    解析: 暂无解析

  • 第22题:

    单选题
    Given: What is the result?()
    A

    The code runs with no output.

    B

    An exception is thrown at runtime.

    C

    Compilation fails because of an error in line 20.

    D

    Compilation fails because of an error in line 21.

    E

    Compilation fails because of an error in line 23.

    F

    Compilation fails because of an error in line 25.


    正确答案: F
    解析: 暂无解析

  • 第23题:

    单选题
    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;


    正确答案: D
    解析: 暂无解析