Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

How to overload new operator in c++

2 Answers  


What are the benefits of oop?

0 Answers  


Can a destructor be called directly?

0 Answers  


What Is a Polymorphism? How many types of polymorphism and whats that use in application?

2 Answers  


Which is the only operator in C++ which can be overloaded but NOT inherited?

8 Answers  


Explain virtual inheritance?

0 Answers  


what is the difference between class and structure in C++?

9 Answers   Aspire, IBS, TCS,


write a program for function overloading?

14 Answers   HCL, InfoCity, TATA,


What is data binding in oops?

0 Answers  


What is the difference between the C & C++?

9 Answers   HCL,


Write a program to accept a number and to print numbers in pyramid format? for eg:for a no. 5 1 212 32123 4321234 543212345

7 Answers  


What is and I oop mean?

0 Answers  


Categories