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
Explain the advantages of inheritance.
What is an interface in oop?
What is encapsulation selenium?
Why is object oriented programming so hard?
What is polymorphism give a real life example?
given a set based questions and 5 questions based on it next data sufficiciency questions 2 and 2/3 english sentence completion with options very easy and 2 synononmys paragraph with 10 questions 10 minutes replace =,-,*,% with -,%,+,* type questions 5 3 questions lik following itssickhere itssickthere itssickhere istsickhere which is nt alike the others very easy
What are the benefits of interface?
State what is encapsulation and friend function?
What is the difference between inheritance and polymorphism?
What is abstraction in oop with example?
What is polymorphism in oop example?
Hi friends I have experience of 6 months in website design and maintanence. Now i am looking for other IT jobs.. to switch platform. please post any interview you know in chennai.
What is this pointer in oop?
How do you explain polymorphism?
What is object and class in oops?