Given the following:
Dog rover = new Puppy("rover"); // Where Puppy extends Dog
A student asked why would you ever want or need a Dog variable point to a Puppy object? The only answer I could come up with is the following:
Suppose we have a game program with Dogs and Puppies. A Puppy may have some special attributes and methods that a Dog does not have. Over the course of the game we may want our variable "rover" to be able to point to a Dog instead of a Puppy.
I'm comfortable with this answer but are there other kinds of use cases where having a Parent variable point to a Child class would be useful?
UPDATE: Thank you everyone for your answers. It's not clear that I'm communicating the question properly or that respondents understand the question I'm trying to ask. Let me try again:
Dog Rover = new Puppy("Rover"); //case 1
Puppy Rover = new Puppy("Rover"); //case 2
In both cases Puppy extends Dog. Other than the reason stated in the original post are there any use cases where case 1 allows us to do something that case 2 would not?
It seems in the answers provided (certainly for the ones using an ArrayList) we can add to the ArrayList either case 1 or case 2 and have the same functionality. In other words, there is no inherent advantage of one case over the other.
Whether we use a Dog variable or a Puppy variable we will still access to the overridden methods, and since a Puppy is a Dog we may add either to a ArrayList.
I'm just trying to confirm that I'm not missing something. If I am missing something, a really clear example would be greatly appreciated.