Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Rani Singh   on Nov 06 In Java Category.

  
Question Answered By: Hu Chalthoum    on Nov 06

When you create a instance of a class  and print  it it gives the address of
the object,

>>>> you are absolutely wrong .... no addresses buddy it gives the hash code
........


and if you want to see the hash code then you have to use the
object.hashCode() method..

>>>> well this will definately give the hash code ...........


you can try this out create an object of a class simply print it and print
the object.hashCode() value both will be different...


>>>>> definitely they will be different but just print
Integer.toHexString(object.hashCode()) ... they will not be different ...
provided that toString() is not over ridden ......

also try printing

System.out.println(object);

and

System.out.println(object.getClass().getName() + '@' +
Integer.toHexString(object.hashCode()));

once again that toString() is not over ridden ......

Share: