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 |
What is debug class?what is trace class? What differences are between them? With examples.
What is Agile methodology?
20 Answers ABC, Accenture, College School Exams Tests, Inmar, Microsoft, Sapient,
WRITE A SIMPLE C++ PROGRAM TO SWAP TWO NOS WITHOUT USING TEMP
what is object oriented programming and procedure oriented programming?
In what situation factory design patterns,DAO design patterns,singleton design patterns should be applied.?
What is the important feature of inheritance?
Can enum be null?
Input: enter the value:1234 output: 1 2 3 4 write a program to get above output.....
4 Answers Bally Technologies, IBM, SoftSol,
What do you mean by overloading?
What is encapsulation selenium?
what are the ways in which a constructors can be called?
What is Difference Between Inheritance and creating object and getting data? means Class A extends B{ B.getMethod();} (OR) Class A{ b obj=new B(); obj.getMethod(); }