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 the real life example of polymorphism?
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.
How long to learn object oriented programming?
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
JAVA is FULLY OBJECT ORIENTED PROGRAMING LANGUAGE?
DIFFRENCE BETWEEN STRUCTURED PROGRAMING AND OBJCET ORIENTED PROGRAMING.
what type of question are asked in thoughtworks pair programming round ?
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?
What is abstraction and encapsulation?
4. What do you mean by a prototype? Define analysis prototype
How do you achieve polymorphism?