Can anyone please explain runtime polymorphism with a real
time example??at what ciscumstances we go for it??
Answer Posted / 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 View All Answers
What is oops concept with example?
Get me an image implementation program.
What is encapsulation with example?
hi, this is raju,iam studying b.tech 2nd year,iam want know about group1 and group2 details, and we can studying without going to any instutions? please help me.
What is abstraction in oop with example?
What is data binding in oops?
what is the drawback of classical methods in oops?
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?
What is the main feature of oop?
What is the difference between a mixin and inheritance?
hi all..i want to know oops concepts clearly can any1 explain??
What is Difference Between Inheritance and creating object and getting data? means Class A extends B{ B.getMethod();} (OR) Class A{ b obj=new B(); obj.getMethod(); }
Which is not an object oriented programming language?
What is class encapsulation?
What is a class in oop?