Originally posted by cm lak:
when I try to print o, why is it printing "InstanceTest@..." instead of "java.lang.Object@....."
Okie, the reference is of type object and the instance is of type InstanceTest. In
java, you can make a base class variable refer to a child class instance. At runtime, when a method on the reference is called, the call actually goes to the implementation in the actual instance(ploymorphism). toString() is the method called when you print any object. toString() is by default defined to print the object definition in the format you have specified.
May be
this tutorial will explain things better.