Can anyone please explain runtime polymorphism with a real
time example??at what ciscumstances we go for it??



Can anyone please explain runtime polymorphism with a real time example??at what ciscumstances we ..

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

Post New Answer

More OOPS Interview Questions

What are classes oop?

0 Answers  


why constructor cannt be declar virtually? why destructor cannt be overloaded?

2 Answers   Infosys,


What does enum stand for?

0 Answers  


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?

0 Answers  


WAP find square root of any number (without using sqrt() )?

3 Answers  






Difference between vector and array

2 Answers  


what is static?

4 Answers  


what is abstract class ? when is used in real time ? give a exp

5 Answers  


design class for linked list and include constructor,destructor,insert option. struct node { int node; struct node &ptr; }

1 Answers   HSBC,


i=20;k=0; for(j=1;k-i;k+=j<10?4:3) { cout<<k; } //please comment on the output

0 Answers  


How to execute business logic for only once ..?even though user clicks submit button multiple times by mistake..? (i disabled JavaScript)

1 Answers  


what is the difference between class and object?

9 Answers  


Categories