9. Write a C++ program showing runtime behavior's of virtual functions with following conditions i. Virtual functions cannot be static. ii. A virtual function can be a friend function of another class. iii. Virtual functions should be accessed using pointer or reference of base class type to achieve runtime polymorphism. iv. The prototype of virtual functions should be the same in the base as well as derived class. v. They are always defined in the base class and overridden in a derived class. It is not mandatory for the derived class to override (or re-define the virtual function), in that case, the base class version of the function is used. vi. A class may have virtual destructor but it cannot have a virtual constructor.
Aucun commentaire:
Enregistrer un commentaire