What are virtual functions?

Answers were Sorted based on User's Feedback



What are virtual functions?..

Answer / qapoo

A function is declared virtual in base class when u are
having same functions in both base and derived classes and
you want to access both the functions with same function
call and its done using base class pointer.
e.g
class base
{
public:
void show(){cout<<"hi"};
};
class derived:pubic base
{
public:
void show(){cout<<"bye";}
};
int main()
{
base *ptr;
base b;
derived d;
ptr=&b;
ptr->show();//base class fn is called
ptr=&d;
ptr->show();//derived class fn is called
return 0;
}

Is This Answer Correct ?    7 Yes 3 No

What are virtual functions?..

Answer / nikhil kapoor

The function which supports run time polymorphysm is called
virtual function...

Is This Answer Correct ?    3 Yes 2 No

Post New Answer

More OOPS Interview Questions

Can anyone please explain runtime polymorphism with a real time example??at what ciscumstances we go for it??

1 Answers  


what is the difference between class to class type conversion and copy constructor ?

2 Answers  


What is persistence in oop?

0 Answers  


There are two base class B1,B2 and there is one class D which is derived from both classes, Explain the flow of calling constructors and destructors when an object of derived class is instantiated.

0 Answers  


why c++ is called OOPS? waht is inherutance? what is compiler?

5 Answers  


me get an assignent n its question is this 1.creat a set as in math i.ea={1,2} 2.insert element in it3. delete element don,t repeat any element 4.union 5. intersection of two sets plz help me i always pray for u n send me at ayeshawzd@hotmail.com f u have c++ how to program 5th addition then it is the 10.9 question in 10th chapter exercise

1 Answers  


what are the realtime excercises in C++?

0 Answers   IBM, Wipro,


What do you mean by inheritance?

0 Answers   IBS,


Write on signed and unsigned integers and give three (3) examples each

1 Answers  


What is the use of fflush(stdin) in c++?

4 Answers   HCL,


Why u change company?

12 Answers   BOB Technologies,


WHAT IS THE DIFFERENCE BETWEEN ABSTRUCTION AND ENCAPSULATION? PLEASE EXPLAIN IT.

7 Answers   ETH,


Categories