alim586
Quiz von , erstellt am more than 1 year ago

Quiz am Comparing objects for equality, erstellt von alim586 am 20/06/2015.

5
0
0
alim586
Erstellt von alim586 vor etwa 9 Jahre
Schließen

Comparing objects for equality

Frage 1 von 3

1

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

Wähle eins der folgenden:

  • WAHR
  • FALSCH

Erklärung

Frage 2 von 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?

Wähle eins der folgenden:

  • WAHR
  • FALSCH

Erklärung

Frage 3 von 3

1

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

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

Wähle eine der folgenden:

  • 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

Erklärung