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.
First of all your code (1st) will NOT give compile error, it gives a RuntimeException though!
The reason is you are trying to put a Dog() into a Cat. Dog is NOT a Cat , so that gives an Exception. It compiles fine because both are sub classes of Animal