I think your wondering why toString is called. When you called print or prinln on an object the toString method of that object is called. Here is the doc
print
public void print(Object obj)
Print 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.
Parameters: obj - The Object to be printed See Also: Object.toString()
class A { public String toString () { return "4"; } } class B extends A { public String toString () { return super.toString() + "3"; } } public class test { public static void main(String[] args) { System.out.println(new B()); } } Compilation succeeds and 43 is printed. But why ? Thanks !!
nata.r<br />**********************************<br />To win is not always success<br />And to lose is not always failure.<br />**********************************