Why if i try to print an object i get the name of the class followed by a hexadezimal representation?

Viewed 55
 MyClass mcc1d = new MyClass(18, "hello");
 System.out.println(mcc1a);

Why is the following the output of the code above?

MyClass@23fc625e
1 Answers

This is because in Java, System.out.println() applied on an object calls .toString(). The default of the .toString()-method returns the class name followed by @ followed by the hash representation of the object.

Related