So, in one of the Java tutorials I was watching, I came across this line of code:
Animal mutt = new Dog();
Where Dog
extends Animal
. This line works, creating a type Animal variable referring to a Dog instance. But I wonder, can't we do this instead?
Dog mutt = new Dog();
Thanks, I hope you can shed light on this.