Since static methods are class members and not instance members, the method that is corresponding to the type of the type of the reference variable will be called.
In your example,
is equivalent to converting the object of class Animal to object of class Dog and then calling the method on it. This works because the class that the compiler sees is Dog class and hence invoke the method corresponding to Dog class.
In the next case, since a is an array that holds Animal objects, the method corresponding to Animal class is invoked.