I am learning Java and I don't understand the difference between these assignments:
Superclass x = new Superclass();
Superclass x = new Subclass();
Subclass x = new Subclass();
Where Subclass extends Superclass. I mean that i know that the the first assignment could take the reference of all the subclasses that extends Superclass and also that the last can accept only the reference of the specific Subclass. I also know that in the second assignment Superclass is the "static type" ( don't know if it's correct to say it) which is checked at compile time and Subclass is the "dynamic type" which is checked at runtime. But I cannot imagine a use case in which is better to choose the second assignment instead of the other two. So if you can explain in what these assignments are different it would be great! Thanks :)