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 |
How to deploy web appliction in web logic ?
What is coupling in oops?
Write a program to find out the number of palindromes in a sentence.
swapping program does not use third variable
What do you mean by Encapsulation?
write a code for this:trailer recordId contains a value other than 99, then the file must error with the reason ‘Invalid RECORD_ID’(User Defined Exception).
Out of 4 concepts, which 3 C++ Follow?
what is use to destroy an object? illustrate.
What is encapsulation in oop?
what is polymorphism?
What is polymorphism? Explain with an example.
what is the virtual function overhead, and what is it used for ? i hope i can get and appropriate answers, thanks a lot....