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

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

3 Answers   PCS,


What is a friend function & its advantage?

1 Answers   MIT,


How many types of access specifier in c# and vb.net?

1 Answers   Infosys,


WHEN A COPY CONSTER IS CALL ?

4 Answers  


What are the types of abstraction?

0 Answers  






what is the usage of clas templates

5 Answers  


what is the definition of incapsulation

2 Answers  


write knight tour problem which is present in datastructure

0 Answers  


Is following functions are said to be overloaded? int add(int a,int b) char *add(int a,int b)

4 Answers  


Why is object oriented programming so hard?

0 Answers  


i am getting an of the type can not convert int to int *. to overcome this problem what we should do?

0 Answers  


for example A,B,C,D are class all the 4 class contain one method who() but the method who() implementaion is differnet among each class. the relation among the 4 class are A is base class and is inherited by B and C.and from this two B and C where D is inherited. the question is i want to display the output who() method in all the classes(A,B,C,D)the output of who() method is diferrent amond all the class(A,B,C,D) ------A------ virtuval who(print a) override | | who(print b) B C override who(print c) | | -------D------ override who(print d)

2 Answers  


Categories