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 |
Why is polymorphism needed?
What type of Job you are providing?
how to create thread in java?
17 Answers IBM, Infosys, Wipro,
Difference between vector and array
Explain the advantages of inheritance.
What is object in oop?
What is inheritance in simple words?
If a=5, b=6, c=7, b+=a%c*2. What is the final value of b?
I have One image (means a group photo ) how to split the faces only from the image?............ please send the answer nagadurgaraju@gmail.com thanks in advace...
What is encapsulation with example?
write a code for this. serial_number contained in the header of the file will be read , if this serial number is less than a previous serial number within a successfully processed file, or is the same as another serial number within a successfully processed file, or if the field contains anything other than 7 digits, then the file must error with the reason ‘Invalid SERIAL_NUMBER’.
Program to check whether a word starts with a capital letter or not.