Can we store child class objects as array elements in Object type array?

class Array17
{
public static void main(String[] args)
{
Object o[]=new Object[10];
o[0]=new Object();
o[1]=new String("altaf");
o[2]=new Integer(10);
for(Object a:o)
System.out.println(a);
}
}
/*
Output:-java.lang.Object@12b6651 altaf 10 null null null null null null null
Explanation:- For object type arrays, we can store either declared type object or
its child class object as array elements.

*/

0 comments: