I've read this question but I'm not fully satisfied by it. Here is my code:
public static void main(String args[]){
Car c = new Car();
System.out.println(c);
System.out.println(c.getClass());
}
Output:
Car@xxx
Car
And I have not understood why in the first case it prints also the hashCode and it does not in the second. I've seen how println(Object obj)
is defined and the methods it uses, and they are the same, in fact, at the deepest level of stack calls, toString()
is defined like this:
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}
So why at the output I can't see "@xxx"?
Thank you in advance.