InterviewSolution
| 1. |
What Is Virtual Function And Pure Virtual Function? |
|
Answer» Virtual function:-To achieve polymorphism, function in BASE class is declared as virtual , By declare virtual we make base class pointer to execute function of any derived class depends on content of pointer (any derived class address). Pure Virtual Function :-This is function used in base class, and its defination has to be provide in derived class, In other pure virtual function has not defination in base it defined as : virtual void fun()=0; This MEANS that this function not GOING to do anything, In case of pure virtual funtion derived function has to IMPLEMENT pure virtual function or redeclare it as pure virtual function. Virtual function:-To achieve polymorphism, function in base class is declared as virtual , By declare virtual we make base class pointer to execute function of any derived class depends on content of pointer (any derived class address). Pure Virtual Function :-This is function used in base class, and its defination has to be provide in derived class, In other pure virtual function has not defination in base it defined as : virtual void fun()=0; This means that this function not going to do anything, In case of pure virtual funtion derived function has to implement pure virtual function or redeclare it as pure virtual function. |
|