Can anyone please explain runtime polymorphism with a real
time example??at what ciscumstances we go for it??
Answer / anumeet
Here is a program of run-time polymorphism.
#include <iostream.h>
#include <string.h>
class father {
char name[20];
public:
father(char *fname) // 1 argument constructor
{
strcpy(name,fname)
}
virtual void show()
{
cout<<"father's name: "<<name<<"\n";
}
};
class son : public father
{
char name[20];
public:
son(char *sname,char *fname): father(fname)
{
strcpy(name,sname);
}
void show()
{
cout<<"son name: "<<sname<<"\n";
}
};
void main()
{
father *fp;
father f1("emraan");
fp=&f1;
fp->show();
son s1("kangana","emraan");
fp=&s1;
fp->show();
}
Is This Answer Correct ? | 3 Yes | 0 No |
What are classes oop?
why constructor cannt be declar virtually? why destructor cannt be overloaded?
What does enum stand for?
IS IT NECESSARY TO INITIALIZE VARIABLE? WHAT IF THE INSTANCE VARIABLE IS DECLARED final ? IS IT NECESSARY TO INITIALIZE THE final VARIABLE AT THE TIME OF THEIR DECLARATION?
WAP find square root of any number (without using sqrt() )?
Difference between vector and array
what is static?
what is abstract class ? when is used in real time ? give a exp
design class for linked list and include constructor,destructor,insert option. struct node { int node; struct node &ptr; }
i=20;k=0; for(j=1;k-i;k+=j<10?4:3) { cout<<k; } //please comment on the output
How to execute business logic for only once ..?even though user clicks submit button multiple times by mistake..? (i disabled JavaScript)
what is the difference between class and object?