Can anyone please explain runtime polymorphism with a real
time example??at what ciscumstances we go for it??



Can anyone please explain runtime polymorphism with a real time example??at what ciscumstances we ..

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

Post New Answer

More OOPS Interview Questions

What is the real life example of polymorphism?

0 Answers  


Question: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date.

0 Answers  


How long to learn object oriented programming?

0 Answers  


Pls...could any one tell me that whether we can access the public data memeber of a class from another class with in the same program. Awaiting for your response Thanku

4 Answers  


JAVA is FULLY OBJECT ORIENTED PROGRAMING LANGUAGE?

3 Answers  






DIFFRENCE BETWEEN STRUCTURED PROGRAMING AND OBJCET ORIENTED PROGRAMING.

5 Answers  


what type of question are asked in thoughtworks pair programming round ?

0 Answers   Thought Works,


what is difference b/w object based and object oriented programming language?

18 Answers   Chaitanya, College School Exams Tests, Educomp, IBM, Infosys, Telko,


143.what is oops principles?

10 Answers  


What is abstraction and encapsulation?

0 Answers  


4. What do you mean by a prototype? Define analysis prototype

1 Answers  


How do you achieve polymorphism?

0 Answers  


Categories