Hi all,
What is the difference between polymorphism and method overloading? Please explain with some suitable examples?
Thanks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
JurePosted Oct 6, 2010, 1:40 PM
You can write a base class, which has everything that your classes have in common, then all you need to do is inherit the base class and just add stuff that is specific to that particular class. So the advantage is that you don't need to write every class from scratch, like when you overload methods.
Then there are interfaces, which is kind of a "plan" that tells you what stuff your class needs to implement, and abstract classes, whose purpose is to be inherited (creation of abstract-class object isn't allowed) - this is useful when you have a base class that contains some common stuff, but is still missing more specific stuff to work properly on its own.
Method overloading is simply making multiple methods (with different parameters) share the same name, but each method still needs to be fully defined.