Skip to main content

Need of Method Overloading

1 reply [Last post]
Joined: 2010-07-29

What is the need of method overloading? What would happen if this feature is not present in Java?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-04-29

Overloading allows you to write more than one method in the same class with the same name, but with different signatures (number and type of arguments). You can use it for example, to simplify your calls, by using the method with the least number of arguments when all defaults are acceptable. Or you can use it when you have more than one way of identifying the same thing, like (String)name and (Long)ID. In these two examples, once the overloaded methods accomplish initialization, whatever job needs to be finished can be done by a common method.

You can also use it in more complex ways, depending on the code within - just a matter of need and creativity.