in the above polymorphism why is it called runtime polymorphism when i can say seeing the code itself that display() function in derived gets executed with ptr->display(),so how does it become runtime polymorphism when i could get decide at compile itself ??????????.....i am new to c++ please help
You're calling the function from a pointer to a Base, which could be pointing to any kind of Base, not just Derived. And so when you call methods from this pointer, it goes to the class of the pointer type (Base) then polymorphism at runtime sets up the correct actual function to be called.
A large scale C++ project could have hundres of classes. Consider the abstract factory pattern where a user of an object is given a base class pointer to something without knowing what the derived type actually is. Of course it is hard to understand the use when you are looking at such a simplistic example. Perform a web search on the aforementioned pattern, and look at some examples. Perhaps then you will understand. In many cases, the construction will occurr in a place that is far removed from where the user of the object makes a function call. The idea here is to minimize compile time dependencies by separating interface from the implementation. Factories build collections of similar objects, and return pointers to the base classes. Now you can code the user classes to the interfaces. Virtual functions must be implemented otherwise the linking will not work. So there will always be some kind of an implementation for virtual functions that the end user doesn't see. However, the interface is like a contractual obligation. Although there could be different ways of meeting the obligation, the obligation must be met somehow.
By the way, the idea behind polymorphism is to be able to perform operations on groups of similar objects uniformly. That is, they share a common interface (such as the function f above) that can be called independent of the actual type.