This is how you find out:
- Look at the API documentation of class java.lang.System
- You see that it has a static member variable called "out", which is a java.io.PrintStream
- Look at the API documentation of class java.io.PrintStream
- You see that it has several overloaded versions of the print(...) method
- For your A object, it uses the print(Object) version
- Look at the API documentation for that method; it says:
API documentation wrote:Prints an object. The string produced by the String.valueOf(Object) method is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.
So now you know that it calls String.valueOf(...) with your object as the argument. The API documentation of String.valueOf(...) says:
API documentation wrote:Returns:
if the argument is null, then a string equal to "null"; otherwise, the value of obj.toString() is returned.
In other words, this calls toString() on your object.