1. abstract function doesn't contain any body but a virtual
function contain body
2. we must be implement the abstract function in derived
class but it is not necessary for virtual function
3. abstract function can only use in abstract class but it
is not necessary for virtual function
4. abstract function are called pure virtual function
Abstract Functions can not have any body or implementation
while virtual Functions can have body or implementation ,abstract functions
must be implementation by derived classes and virtual not must implementation
by derived classes,both are override in derived classes
Abstract function:-->
1) An abstract function has no implementation. It can only
be declared. This forces the derived class to provide the implementation of it.
2) Abstract means we MUST override it.
3) An abstract member is implicitly virtual. Abstract can be
called as pure virtual in some of the languages.
Virtual Function:-->
1) Virtual Function has an implementation. When we inherit
the class we can override the virtual function and provide our own logic.
2) We can change the return type of Virtual function while
implementing the function in the child class(which can be said as concept of
Shadowing).
3) Virtual means we CAN override it.
No comments:
Post a Comment