• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.object

 
Kota li
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which of the following classes java.lang.Object override hashCode() method in Object class
java.lang.String
,, ,, .StringBuffer
.Number
.Byte
which of them override
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15480
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can find the answer by looking up the API documentation of those classes. If the documentation doesn't mention a hashCode() method, then the class doesn't override it.
 
Vikrant Sahdev
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String and Wrapper classes override equals() method. And by contract, if you override equals() method, you need to override hashCode()method as well.

StringBuffer doesnt override equal()method and therefore doesnt override hashCode()method as well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic