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 |
How to overload new operator in c++
What are the benefits of oop?
Can a destructor be called directly?
What Is a Polymorphism? How many types of polymorphism and whats that use in application?
Which is the only operator in C++ which can be overloaded but NOT inherited?
Explain virtual inheritance?
what is the difference between class and structure in C++?
write a program for function overloading?
14 Answers HCL, InfoCity, TATA,
What is data binding in oops?
What is the difference between the C & C++?
Write a program to accept a number and to print numbers in pyramid format? for eg:for a no. 5 1 212 32123 4321234 543212345
What is and I oop mean?