If I have the following situation where I define a class Animal and another class Dog that extends Animal with the following two lines of code:
1) Dog d = (Dog) new Animal(); //explicit downcast
2) Animal a = new Dog(); //automatic upcast
What are the pros and cons of defining two animals this way? Specifically, in what situations would I prefer (1) over (2) and vice versa?
From what I understand, we downcast to have access to Dog's methods, but then why not just call it a dog?
Thanks in advance!