what is virtual function?

Answer Posted / nk

A virtual function is basically a like normal function but
we can override the function in the derived classes.
Now when we want to access like (fn)

Base * bptr = new Derived();
bptr->fn(); then function of the derived class will be
called only if the function is marked as virtual in the
base class.

i.e the virtual keywork tells to use the function of the
class to which it is pointing to and not to the Base class.
This is called runtime polymorphism.

Is This Answer Correct ?    24 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the benefits of polymorphism?

622


What is encapsulation and abstraction? How are they implemented in C++?

637


What does and I oop mean in text?

624


c++ program to swap the objects of two different classes

1761


What is destructor in oop?

623






What is destructor example?

596


can inline function declare in private part of class?

3658


What is the real time example of inheritance?

639


Write a c++ program to display pass and fail for three student using static member function

2814


What is the benefit of oop?

570


What is constructor in oop?

587


What is a superclass in oop?

667


How do you achieve runtime polymorphism?

569


What is static in oop?

588


How can you overcome the diamond problem in inheritance?

768