i think Anvi you are confused about how static methods are invoked
just remember what Keith Lynn has written
"when a static method is invoked using a reference, the type of the reference used determines which static method is invoked."
your question is
for the x=1 , a[1] = new Dog() and hence we can write
Animal a = new Dog();
a.doStuff();
output will be d:
no you are wrong. output will be a:
as you see the reference is of Animal type so doStuff() method from Animal class is invoked. so a: will be printed. (for a[x].doStuff()
and when reference is converted from Animal class to Dog class using explicit cast, doStuff() method from Dog class is invoked printing d:
(for ((Dog)a[x]).doStuff()
Pankaj Shinde