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 static in oop?
What is encapsulation process?
write a C++ program for booking using constructor and destructor.
What are different oops concepts?
What is encapsulation c#?
Can you explain polymorphism?
What is difference between abstraction and encapsulation?
How is polymorphism achieved?
What is object and example?
What are benefits of oop?
What is the difference between inheritance and polymorphism?
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
Why is there no multiple inheritance?
Write a program to sort the number with different sorts in one program ??
Whats is abstraction in oops?