toString method why its not called implicitly for objects
997192Apr 20 2013 — edited Apr 21 2013class Building { }
public class Example
{
public static void main()
{
Building b = new Building();
String s = (String)b;
}
}
in the 5th Line it shows error that cannot cast building type to string..
but all classes have the toString method which is called whenever we give the object arguement in System.out.println();
the following code compiles
class Building { }
class Example
{
public static void main()
{
Building b = new Building();
System.out.println(b);
}
}
can anyone explain this?