This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
You've declared the variable as Animal, and Animal.voice() returns Object. Although you know that the variable a contains an instance of Dog, the compiler does not "know" it and therefore expects that a.voice() returns Object.
This behavior of the compiler is not an error, it was designed this way. This is a trivial case. However, there might be cases in which such conclusions about actual type of a variable (if at all possible) might require extensive analysis. Therefore, the compiler follows a simple rule: a type of the variable is always determined by its declared type, regardless of its actual contents.