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

What are classes oop?

0 Answers  


What is the real life example of polymorphism?

0 Answers  


what is pointers

7 Answers   Exilant,


can we make game by using c

1 Answers   SmartData,


What is the difference between inheritance and polymorphism?

0 Answers  






Base class has two public data members. How can i derive a new class with one datamember as public and another data member as private?.

2 Answers  


What is abstraction in oops?

0 Answers  


OOP'S advantages of inheritance include:

1 Answers   Infosys,


what is the difference between inter class and abstract class...?

0 Answers  


What is cohesion in oop?

0 Answers  


What is multiple inheritance?

9 Answers   TCS,


Explain the concept of abstracion and encapsulation with one example. What is the difference between them?

3 Answers   PCS,


Categories