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

char* ptr = "Rahul"; *ptr++; printf("%s",ptr); What will be the output

9 Answers   Persistent,


DIFFRENCE BETWEEN STRUCTURED PROGRAMING AND OBJCET ORIENTED PROGRAMING.

5 Answers  


string is a class or data type in java?

3 Answers  


What is polymorphism used for?

0 Answers  


Name a typical usage of polymorphism

3 Answers  






What is overriding vs overloading?

0 Answers  


What causes polymorphism?

0 Answers  


what is virtual function in c++

6 Answers  


How many human genes are polymorphic?

0 Answers  


What is inheritance and how many types of inheritance?

0 Answers  


Write a program to reverse a string using recursive function?

0 Answers   TCS,


explain defference between structure and class with example

1 Answers  


Categories