Parent parent = new Child();
parent.someMethod();
In what situations,assinging like above is useful or what is the logical explanation behind it? instead of the following:
Child child = new Child();
child.someMethod();
In both the cases,Child's method is only going to be called,anyway.So,why this kind of representation is allowed? Isn't it an unnecessary feature allowed in the design?
The only reason I could come up with,depending on some fiddling I did is that,it lets you know that "someMethod()" is not available in the Parent if it is not present in the Parent,at the time of writing "parent.someMethod()"!
Can you please shed some light as to how it is useful/necessary and give me some perspective related to object oriented concepts? I know it relates to Polymorphism here.But I don't find any necessity to use such representations.
Practical real-world example is much appreciated. Thanks.
I check the following SO question,but I don't feel like I have the answers I am looking for. Using superclass to initialise a subclass object java