class Super
{
public String toString()
{
return "4";
}
}
public class SubClass extends Super
{
public String toString()
{
return super.toString()+"3";
}
public static void main(String[] args)
{
System.out.println( new SubClass() );
}
}
For the above, ethuware states the answer is 43, but why is it 43 when the new SubClass did not even call the toString method nor is in the constructor, is it an error?
Last edited by admin on Tue Oct 01, 2013 11:12 am, edited 1 time in total.
Reason:Added [code] tags. Please specify Question ID as well.
The println method calls toString on the object that you passed in as an argument. So toString() will be called on new SubClass() object and that value will then be printed.