What is method overloading?

oop, overloading

Solution

That's just a very general way of describing it. Method overloading allows you to use a single method name, but "overload it" (provide more than one version) depending on "context" (which is typically the type or number of arguments passed in). Since each method is separate, they can cause a "different outcome".

For example, using C#, you can write:

void Foo()  // Version with no arguments
{
}

void Foo(int arg) // Version with a single int
{
}

void Foo(string arg1, double arg2) // Version with string and double parameters
{
}

Problem

I've found resources that say method overloading is the ability for a language to use the same method with a different outcome, depending on context. Somehow, when I read other definitions, I fell like that's not the whole definition. Is there more to method overloading?

Original source

Related problems