Quiz
Comparing objects for equality
Questions in this quiz (3)
1The default implementation of the equal method compares only whether two object variables refer to the same object
- ATrue
- BFalse
2See 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?- ATrue
- BFalse
3Why is the next equals method in conflict with the contract for the equals method
public boolean equals (Object anObject){
return true;
}- ABecause it returns true, even for null values passed to this method
- BBecause it doesn't compare the values of the instance variables of the objects
- CBoth answers are true
Information
- Description
- Quiz on Comparing objects for equality, created by alim586 on 20/06/2015.
- Author
- alim586
- Language
- English
- Views
- 21
- Tags
- Rating
- No ratings yet Rate this quiz