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...

What are the different forms of polymorphism??

Answer Posted / amit

There are two types of polymorphism:-
1.Compile time polymorphism
This is achieved by:
- Function overloading
- Operator overloading
2.Run time polymorphism
This is achieved through inheritance and virtual functions.
In this, base class has one or more virtual functions which
are overridden in the derived class. And then base class
pointer is used to access base or derived class virtual
function.

Example:-

class base {
public:
virtual void func() {
cout << "In base class" << endl;
}
};

class derived {
public:
void func() {
cout << "In derived class" << endl;
}
};

int main(){
base *bp, b;
derived d;

bp = &b;
bp->func(); // base class func() will be called

bp = &d;
bp->func(); // derived class func() will be called
return 0;
}

Here, the decision to call base or derived class func() is
taken at run time.

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is abstract thinking intelligence?

1110


What is a superclass in oop?

1222


What is and I oop mean?

1280


What is solid in oops?

1208


What is encapsulation oop?

1107


What do you mean by overloading?

1131


What is polymorphism programming?

1181


if i have same function with same number of argument but defined in different files. Now i am adding these two files in a third file and calling this function . which will get called and wht decide the precedence?

3606


How is polymorphism achieved?

1114


What is static modifier?

1330


Which is better struts or spring?

1117


Can you inherit a private class?

1144


what is difference between class template and template class?

2716


What is overriding vs overloading?

1112


Hi friends I have experience of 6 months in website design and maintanence. Now i am looking for other IT jobs.. to switch platform. please post any interview you know in chennai.

2243