Why is the output? : Sphere 0
Somehow it's calling the toString() method implicitly? How does this work ?
class BerylliumSphere {
private static long counter = 0;
private final long id = counter++;
public String toString() {
return "Sphere " + id;
}
}
public class Test {
public static void main (String[] args) {
BerylliumSphere spheres = new BerylliumSphere();
System.out.println(spheres);
}
}
// output: Sphere 0