Q:

Write some important rules associated with virtual functions?

0

Write some important rules associated with virtual functions?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer:

Below we are mentioning few rules for virtual function in C++.

  • Virtual functions cannot be static and also cannot be a friend function of another class.
  • Virtual functions should be accessed using pointer or reference of base class type to achieve run time polymorphism.
  • The prototype of virtual functions should be the same in the base as well as derived class.
  • They are always defined in the base class and overridden in the 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.
  • A class may have a virtual destructor but it cannot have a virtual constructor.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Interview Questions and Answers(2022)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Name the Operators that cannot be Overloaded in c+... >>
<< What is the virtual function?...