What are virtual functions?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is super in oop?

871


What is solid in oops?

822


What is ambiguity in inheritance?

873


what are the ways in which a constructors can be called?

1815


Why multiple inheritance is not possible?

824


What is difference between pop and oop?

839


What is overloading and its types?

843


What is this pointer in oop?

817


What is the example of polymorphism?

773


assume the program must insert 4 elements from the key board and then do the following programs.sequential search(search one of the elements),using insertion sort(sort the element) and using selection sort(sort the element).

1913


write a code for this:trailer recordId contains a value other than 99, then the file must error with the reason ‘Invalid RECORD_ID’(User Defined Exception).

1928


What is the main feature of oop?

918


What is polymorphism give a real life example?

785


Please send ford technologies placement paper 2 my mail id

1865


Whats oop mean?

806