Comparing objects for equality

Descrição

Quiz sobre Comparing objects for equality, criado por alim586 em 20-06-2015.
alim586
Quiz por alim586, atualizado more than 1 year ago
alim586
Criado por alim586 mais de 9 anos atrás
8
0

Resumo de Recurso

Questão 1

Questão
The default implementation of the equal method compares only whether two object variables refer to the same object
Responda
  • True
  • False

Questão 2

Questão
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?
Responda
  • True
  • False

Questão 3

Questão
Why is the next equals method in conflict with the contract for the equals method public boolean equals (Object anObject){ return true; }
Responda
  • 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

Semelhante

Java Week 5 Object Oriented Programming
Troy Bowlin
Java Practice 1
Ummm No
Religion and Human Rights
Jessica Phillips
Label the Classroom
Robert Caceres
OOP (Object Oriented Programming)
Adam Cook
Servion - Java Questionnaire
rohit.benedict
Java Practice 2
Ummm No
Java Core. Basics
Gadget
Programming Review
Shannon Anderson-Rush
Useful String Methods
Shannon Anderson-Rush
JavaScript Fundamentals
Andrew Watters