Chandra:
Hi Srikanth,
Nothing like garbage value as you see in C, C++;
It if Nameoftheclass@hashCode() of your object.
hashCode() is a public method declared in the Object class. Every class inherits that method.
You add the following to your class and see the output:
code:
public int hashCode() {
return 32af;
}
Now you try to print the object using println();
you will get output like:
YourClassName@32af
Got it?
Regards,
cmbhatt
^
I tried putting the above hashCode() method as
-----------------------------------------------
public class Tempo
{
public int hashCode()
{
return 32af;
}
public static void main(
String[] args)
{
Tempo temp = new Tempo();
System.out.println(temp);
}
}
-----------------------------------------------
While compiling, it give an error like this:
_------------------------------------------------
C:\Practice\RA\java\2007\Tempo.java:10: ';' expected
return 32af;
^
1 error
Tool completed with exit code 1
-------------------------------------------------
When I don't override hashCode(), println prints probably memory address.
Why do you think it might be giving the error?
Thanks,
Raghav