Virtual Function:- When we used same function in both the child and parent class,than we apply virtual function in parent class.Virtual fun...
Virtual Function:-When we used same function in both the child and parent class,than we apply virtual function in parent class.Virtual function has dynamic binding function because method calling is resolve in run time.We put virtual keyword in parent class when we use this logic in our class.It is used in c ++,java,c#(c sharp) etc.
Example:-
#include<iostream.h>
#include<conio.h>
class parent
{
public:
virtual void show()
{
cout<<"THIS IS PARENT CLASS";
}
};
class child:public parent
{
public:
void show()
{
cout<<"THIS IS CHILD CLASS";
}
};
void main()
{
parent p;
child c;
parent*ptr;
ptr=&p;
ptr->show();
ptr=&c;
ptr->show();
getch();
}
That's all about Virtual Functions(in oops and data structure).
Example:-
#include<iostream.h>
#include<conio.h>
class parent
{
public:
virtual void show()
{
cout<<"THIS IS PARENT CLASS";
}
};
class child:public parent
{
public:
void show()
{
cout<<"THIS IS CHILD CLASS";
}
};
void main()
{
parent p;
child c;
parent*ptr;
ptr=&p;
ptr->show();
ptr=&c;
ptr->show();
getch();
}
That's all about Virtual Functions(in oops and data structure).
If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.
COMMENTS