Which is the difference between overloading and polymorphism?

Recommended Answers

All 7 Replies

Polymorphism is a category of programming language features that meet certain requirements[1] and overloading is a member of that category.

[1] Specifically: using the same name to refer to and work with different entities in a safe and well-defined manner.

Overloading is one thing, and polymorphism is another. Look at the definitions on the internet and then use thinking to figure how they are related and unrelated.

Typically when you overload something (a function for example), you're giving a new option as to how the client/programmer can use that function.

Polymorphism is slightly more difficult to describe. It's as if you're giving new meaning to an existing procedure in a way that is transparent to the client.

Note: Polymorphism is one of the big traits of Design Patterns, but not the only trait of course.

in c++ when we use operator overloading
we actualy change the name of any function into a operator like +,-,*,/ .
the function is declared:
return operator +(parameters)
{
}
in the programe
when we need to call it
class type a,b,c;
a.enter();
b.enter();
c=a+b;
in polymorphism we can defined different name for same entity.

Which is the difference between overloading and polymorphism?

The difference between polymorphism and method overloading is in the time when the actual method to execute is determined. The reason for this is that when a method is overloaded, such as in:
account = new BankAccount();
account = new BankAccount(1000);
The compiler can tell which constructor to use by the method signature, including the number and types of parameters provided. This selection of a method to use at compile time, before the program ever runs is called early binding.

for more info please visit http://www.techyv.com/questions/what-difference-between-function-polymorphism-and-overloading

Could you please stop pulling old threads back up? This one is over 3 years old already...

Overloading is a type of polymorphism(more like a branch of it). Better still, let me put it this way:

polymorphism in the context of object-oriented programming, is the ability to create a variable, a function, or an object that has more than one form.

The terms overloading may refer constructor and method overloading, in computer science, a type of polymorphism where different functions with the same name are invoked based on the data types of the parameters passed.

i have made their similarities in bold so you can easily pick on that. Having said this, you may come across things like function overloading, operator overloading and so on.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.