Which two are valid constructors for Thread?

  1. Thread(Runn

Loading

Practice Threads –

Which two are valid constructors for Thread?

  1. Thread(Runnable r, String name)
  2. Thread()
  3. Thread(int priority)
  4. Thread(Runnable r, ThreadGroup g)
  5. Thread(Runnable r, int priority)

Which of the following statements is true?

Loading

Practice Assertions –

Which of the following statements is true?

Which statement is true about assertions in the Java programming la

Loading

Practice Assertions –

Which statement is true about assertions in the Java programming language?

Which statement is true?

Loading

Practice Assertions –

Which statement is true?

Which of the following statements is true?

Loading

Practice Assertions –

Which of the following statements is true?

x = 0; 
if (x1.hashCode() != x2

Loading

Practice Declarations and Access Control –

x = 0; 
if (x1.hashCode() != x2.hashCode() )
x = x + 1;
if (x3.equals(x4) )
x = x + 10;
if (!x5.equals(x6) )
x = x + 100;
if (x7.hashCode() == x8.hashCode() )
x = x + 1000;
System.out.println("x = " + x);

and assuming that the equals() and hashCode() methods are property implemented, if the output is “x = 1111“, which of the following statements will always be true?

Which two statements are true about comparing two instances of the

Loading

Practice Declarations and Access Control –

Which two statements are true about comparing two instances of the same class, given that  the equals()  and  hashCode() methods have been properly overridden?

  1. If the equals() method returns true, the hashCode() comparison == must return true.
  2. If the equals() method returns false, the hashCode() comparison != must return true.
  3. If the hashCode() comparison == returns true, the equals() method must return true.
  4. If the hashCode() comparison == returns true, the equals() method might return true.

Which of the following statements about the hashcode()

Loading

Practice hashCode() method –

Which of the following statements about the hashcode() method are incorrect?

  1. The value returned by hashcode() is used in some collection classes to help locate objects.
  2. The hashcode() method is required to return a positive int value.
  3. The hashcode() method in the String class is the one inherited from Object.
  4. Two new empty String objects will produce identical hashcodes.

class Test1 {     
public int

Loading

Practice hashCode() method –

class Test1 {     
public int value;
public int hashCode() {
return 42;
}
}
class Test2 {
public int value;
public int hashcode() {
return (int)(value^5);
}
}

which statement is true?