The field value is resolved with the declared type of the field, i.e. Animal.
The statement:
a = (Dog)a;
does not change the declared type of a. The reference variable a will always be of (declared) type Animal and you will not be able to change that. The only way to access the instance variable s in class Dog is to do it as done on line 3.
For more information, please check out
JLS 8.3.3.2 Example: Hiding of Instance Variables [ February 13, 2003: Message edited by: Valentin Crettaz ]