Comparing objects for equality

Beschreibung

Quiz am Comparing objects for equality, erstellt von alim586 am 20/06/2015.
alim586
Quiz von alim586, aktualisiert more than 1 year ago
alim586
Erstellt von alim586 vor fast 9 Jahre
5
0

Zusammenfassung der Ressource

Frage 1

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

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

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
Zusammenfassung anzeigen Zusammenfassung ausblenden

ähnlicher Inhalt

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