You are right: as a rule you always want to put the same type of objects into an Array. The example I gave was deliberately poor programming, which is why I included the disclaimer, "(beware, BAD CODING AHEAD ...):".
I was not trying to show how one should program, but simply trying to answer the question posed, showing the different between referent type (Object) and actual instance type (
String, Point and ArrayList).
The referent type is used at compile time to verify that the given object implements the referenced message. The actual object instance type is used at run time to resolve the method to the appropriate class.
Maybe I should have used an ArrayList or Vector instead of an Array. With ArrayLists (and other collections) you dump in "Object" instances and all you get back are "Object"s. To call meaningful methods on them you must cast them back to the desired type.
Mrudul's original question was whether the runtime class of an object can be different from the created class. The answer is a qualified "yes". If you say:
Object myObj = new String("abc def");
To the compiler "myObj" is a "java.lang.Object" type, and the only methods you can invoke on it are those in "Object". However at runtime the JVM will correctly recognize that "myObj" is actually a "java.lang.String". The referent type is "java.lang.Object", but the actual object instance is "java.lang.String".
I think I've officially beat this dead horse ...