You have a lower case s in the dog's doStuff() method, so it never gets invoked!
If it was coded correctly the second line would have printed 'd:a:if instance of dog', because when you casted the animal that is a dog, to a dog, you would have invoked the dog's doStuff() method (not the animal's one!).
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 = 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()