• 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

Doubt from mock exam

 
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In one of the mock exams it is given that the statement "The Hashcode method in the String class is the one inherited from class object" as incorrect.
But it is right ?Am I right?
Veena
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think what is meant is, that the hashcode method is overridden in String. Offcourse Object has the hashcode method but that wouldn't calculate a proper hashcode for a String object. By overriding it one can say that String takes care of his own hashcode and is not depending on Object for it, other than that object declares it in the interface of Object and therefore all subclasses.
Hope this helps?
 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The statement is correct. The String class implements both the equals method and the hashcode method. I'm too lazy to look it up right now, I think it is just a return 0 or something like that. In fact all the wrapper objects override those 2 methods
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The statement is correct. The String class overides the equals and hashcode method.
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mean the answer given in the mock exam is wrong right?This question was from Bill Brodgen's exam simulation applet.I scored 26/43 .Please anybody correct this.Coz these kinda questions make me postpone my decision to schedule exam.
Thanks
Veena
 
Damien Howard
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

"The Hashcode method in the String class is the one inherited from class object" as incorrect.


That is true the statement is incorrect. The methods have been overridden so they are not the ones inherited from the object class
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh! I got it.Thanks
Veena
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic