You are here:

C++/polymorphism

Advertisement


Question
hii!
polymorphism means one message peforms different operations on the object which it receives.
then " what is the benefit of polymorphism in c++?"?why polymorphism?
suppose you consider function overloading.
what is the benefit of using same function for different purposes?
can you explain clearly?

Answer
Hello,

polymorphism occurs at run time while function overloading occurs at compile time,. That said, they are both advantages in that they reduce writing different functions for related objects. say for example you have a bird class..where there are different kind of birds, the ostrich, the kiwi, the sparrows and so on..it would be against OOP principle to start writing different function to identify each individual bird type. you could just write a single function that shows the relationship between these different birds. Code-reuse is part of OOP and that is where polymorphism(having different operation) and function overloading come in. I hope this clarifies your question?

stay blessed

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


henry

Expertise

I can confidently answer any question both basic and advanced in C++. Areas like templates, algorithms, Gui and design patterns are of interest to me. i will not answer questions about web programming.

Experience

I have a 3- year- work experience in software Engineering.

Education/Credentials
I am a bachelor of Engineering graduate

©2016 About.com. All rights reserved.