-8
class RefDem
{
    public void m1()
    {
      System.out.println("m1() method....");
    }
}
class RefDemo
{
   public static void main(String[] args)
    {
   //d is object of RefDem class
    RefDem d=new RefDem();
    d.m1();
   System.out.println("d :"+d);
  System.out.println("d hash code :"+d.hashCode());
}
}

output:

m1() Mehtod
d : RefDem@1e5e2c3  //please explain what is this value
d hash code : 31843011   //please explain what is this
Luca
  • 9,259
  • 5
  • 46
  • 59
faisal khan
  • 47
  • 1
  • 1
  • 3
  • 7
    This question appears to be off-topic because the answer for it can be found in any manual or even javadocs – Alexey Malev Jun 02 '14 at 12:58
  • Just read :http://en.wikipedia.org/wiki/Java_hashCode%28%29 – akash Jun 02 '14 at 13:00
  • possible duplicate of [How is hashCode() calculated in Java](http://stackoverflow.com/questions/2427631/how-is-hashcode-calculated-in-java) – earthmover Jun 02 '14 at 13:03
  • You should take a look at [code of `toString()`](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8-b132/java/lang/Object.java?av=f#235) method from `Object` class. – Pshemo Jun 02 '14 at 13:06

2 Answers2

0

The first is the standard output for the toString() method. See here.

The second is the hashcode for this object.

Dawnkeeper
  • 2,844
  • 1
  • 25
  • 41
0

You did not override toString and hashValue, so the implementations from Object are used.

toString() returns a String consisting of the class name (RefDem) and the memory location in hexadecimal form (1e5e2c3) seperated by "@".

"d :" + d is equivalent to "d :" + d.toString() so you get "d :RefDem@1e5e2c3"

The hashCode implementation of Object returns the memory location of the Object (as int) which is 31843011 (note that 31843011 == 0x1E5E2C3)

fabian
  • 80,457
  • 12
  • 86
  • 114