Comparing objects for equality

Descripción

Test sobre Comparing objects for equality, creado por alim586 el 20/06/2015.
alim586
Test por alim586, actualizado hace más de 1 año
alim586
Creado por alim586 hace casi 9 años
5
0

Resumen del Recurso

Pregunta 1

Pregunta
The default implementation of the equal method compares only whether two object variables refer to the same object
Respuesta
  • True
  • False

Pregunta 2

Pregunta
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?
Respuesta
  • True
  • False

Pregunta 3

Pregunta
Why is the next equals method in conflict with the contract for the equals method public boolean equals (Object anObject){ return true; }
Respuesta
  • 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
Mostrar resumen completo Ocultar resumen completo

Similar

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