I know what is the use of Run Time Polymorphism in an Object Oriented programming language. For example Base class Superhero would be useful to define basic abstract properties of a Superhero that can be inherited and extended in different Super Heroes for example Batman.
I also know that we use inheritance when there is an is-a relationship, for example, Superman is-a Superhero, and we can use a Base class pointer to point to a Derived class object for example...
Superhero *h = new Spiderman();
is valid.
But I want to know what are the circumstances where we would need to do something like this, why can't we just use...
Spiderman *s_man = new Spiderman()
What situation or circumstances would force us to use Base class pointer to hold Child class object.
I would be thankful if someone can make this clear to me.
deleteanySuperHero *. That should be enough to explain whySuperhero *hwould be used. - PaulMcKenzieI know what is the use of Run Time Polymorphism in an Object Oriented programming language.I suspect that you don't. Run time (object oriented) polymorphism can only be achieved by pointing to a derived object with a base pointer (or a reference). When you know what run time polymorphism is used for, the answer will become obvious. - eerorikaSpiderman s_man. - Chris Drew