// In this example, the pointer is of type base but it points to the derived class object. // The method display() is virtual in nature. Hence in order to resolve the virtual method // call, the context of the pointer is considered, i.e., the display method of the derived // class is called and not that of the base. If the method was non virtual in nature, the // display() method of the base class would have been called. #include using namespace std; class base { public: virtual void display() { cout<<"\nBase"; } }; class derived : public base { public: void display() { cout<<"\nDerived"; } }; int main() { base *ptr = new derived(); ptr->display(); getchar(); return 0; }