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
Which language is not a true object oriented programming language?
Why it is called runtime polymorphism?
What is the point of polymorphism?
Can private class be inherited?
can inline function declare in private part of class?
What is meant by oops concept?
What do you mean by variable?
How long to learn object oriented programming?
What are the 3 principles of oop?
What type of loop is a for loop?
Why is it so that we can have virtual constructors but we cannot have virtual destructors?
What does no cap mean?
What is coupling in oop?
Can abstract class have normal methods?
What is encapsulation c#?