• 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

System.out.println(this)

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
john hunt's mock exam
Q17.
public class Test{
static int total = 10;
public static void main(String args []){
new Test();
}
public Test(){
System.out.println("In test");
System.out.println(this);
int temp = this.total;
if (temp > 5){
System.out.println(temp);
}
}
}
the output is:
In test
Test@73d6a5
10
can anyone tell me what this 73d6a5 refers to?
thanks
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is the hashCode converted to hexadecimal. If you call the hashCode() method on the object and convert it to hex, that's the number you'll get.
From API:
The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())

[This message has been edited by Jim Hall (edited December 19, 2001).]
 
patrick tang
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does that mean
System.out.println(this)
is equivalent to
System.out.println(String.valueOf(this))
or
System.out.println(this.toString())?
after reading api, i'm still a little bit
confused. i tested and both worked
reply
    Bookmark Topic Watch Topic
  • New Topic