• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

K&B page 448 Question on GC

 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
5. What two statements are true about *properly* overridden hashCode() and equals() methods?
A. hashCode() doesn�t have to be overridden if equals() is.
B. equals() doesn�t have to be overridden if hashCode() is.
C. hashCode() can always return the same value, regardless of the object that invoked it.
D. If two different objects that are not meaningfully equivalent both invoke hashCode(), then hashCode() can�t return the same value for both invocations.
E. equals() can be true even if it�s comparing different objects.
Answers: c,e
My doubts:
[1] What does *properly* mean ? Legal / appropriate / efficent
[2] Could someone try to explain why c,e are right? I dont quite get the explanation given in the book.
Thanks,
Cathy.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
c)

e)

e) if you will run this with over-reidden equals() method, it will return true else it will return false.
hope this will help.
[ October 02, 2003: Message edited by: MSanjeevMehra ]
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Refer to page 444 of K&B. Hope this helps.
 
reply
    Bookmark Topic Watch Topic
  • New Topic