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 |
Is oop better than procedural?
What do we mean by a hidden argument in a function?
What is the important feature of inheritance?
what is costructor?
what uses of c++ language?
what is different between oops and c++
What is conditional Compilation?
Which type does string inherit from?
Templates mean
What is polymorphism oop?
what is oppes
What is class encapsulation?