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
any one please tell me the purpose of operator overloading
Can you inherit a private class?
What are the 4 main oop principles?
What is oops with example?
Why is it so that we can have virtual constructors but we cannot have virtual destructors?
Get me an image implementation program.
What do you mean by abstraction?
write knight tour problem which is present in datastructure
class CTest { public: void someMethod() { int nCount = 0; cout << "This is some method --> " << nCount; } }; int main() { CTest *pctest; pctest->someMethod(); return 0; } It will executes the someMethod() and displays the value too. how is it possible with our creating memory for the class . i think iam not creating object for the class. Thanks in Advance... Prakash
What is class and example?
2. Give the different notations for the class.\
What is meant by multiple inheritance?
What is constructor overloading in oop?
Can you explain polymorphism?
What is inheritance write a program to show use of inheritance?