Zusammenfassung der Ressource
Frage 1
Frage
The default implementation of the equal method compares only whether two object variables refer to the same object
Frage 2
Frage
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?
Frage 3
Frage
Why is the next equals method in conflict with the contract for the equals method
public boolean equals (Object anObject){
return true;
}
Antworten
-
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