alim586
Quiz por , criado more than 1 year ago

Quiz sobre Comparing objects for equality, criado por alim586 em 20-06-2015.

5
0
0
alim586
Criado por alim586 aproximadamente 9 anos atrás
Fechar

Comparing objects for equality

Questão 1 de 3

1

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

Selecione uma das opções:

  • VERDADEIRO
  • FALSO

Explicação

Questão 2 de 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?

Selecione uma das opções:

  • VERDADEIRO
  • FALSO

Explicação

Questão 3 de 3

1

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

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

Selecione uma das seguintes:

  • 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

Explicação