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

Is oop better than procedural?

0 Answers  


What do we mean by a hidden argument in a function?

1 Answers   TCL,


What is the important feature of inheritance?

0 Answers   BPL,


what is costructor?

1 Answers  


what uses of c++ language?

3 Answers  






what is different between oops and c++

0 Answers   IIT,


What is conditional Compilation?

3 Answers   emc2, HCL,


Which type does string inherit from?

0 Answers  


Templates mean

0 Answers  


What is polymorphism oop?

0 Answers  


what is oppes

2 Answers  


What is class encapsulation?

0 Answers  


Categories