alim586
Quiz by , created more than 1 year ago

Quiz on Comparing objects for equality, created by alim586 on 20/06/2015.

5
0
0
alim586
Created by alim586 almost 9 years ago
Close

Comparing objects for equality

Question 1 of 3

1

The default implementation of the equal method compares only whether two object variables refer to the same object

Select one of the following:

  • True
  • False

Explanation

Question 2 of 3

1

See the following equals method defined in class BankAccount.

class BankAccount(){

String accNumber;
int accType;

public boolean equals (Object obj){
if(obj instanceOf BankAccount){
BankAccount b = (BankAccount) obje;
return(acctumber.equals(b.accNumber) && accType == b.accType);
}
return false;
}
}
Does this method violates the contract for the equals method?

Select one of the following:

  • True
  • False

Explanation

Question 3 of 3

1

Why is the next equals method in conflict with the contract for the equals method

public boolean equals (Object anObject){
return true;
}

Select one of the following:

  • Because it returns true, even for null values passed to this method

  • Because it doesn't compare the values of the instance variables of the objects

  • Both answers are true

Explanation