File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes function overloading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "function overloading" Watch "function overloading" New topic

function overloading

neeni maur

Joined: Jul 03, 2008
Posts: 4
ny 1 can tell me why we use methode or constuctor overloading??
dose it related in terms of memory ???
Steve Luke

Joined: Jan 28, 2003
Posts: 4181

It has nothing to do with memory. Method overloading provides makes an API easier to use by providing the same function name to call for different parameters. If I wanted to print content to console I can use


It would be tedious and annoying if there was no method overloading and I had to do something like:


You would have a bunch of methods that do the same thing but for different input types, and all with slightly different names. Since they all conceptually do the same thing, to make it easier on the caller, we can provide 1 method name, but many different parameter inputs to handle the different types of objects with a simple API:

Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

neeni maur wrote: ny 1 can tell me why we use methode or constuctor overloading??
dose it related in terms of memory ???

Constructor are special methods which takes the same name of the declared class. So, the same rule quoted by Steve Luke applies for constructor also.

Simple example: String class constructors.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 45255
Please don't write "ny" for "any"; it can cause no end of confusion to people who didn't grow up speaking English and automatic tools which think it means "New York."

Please look at this FAQ.
I agree. Here's the link:
subject: function overloading
It's not a secret anymore!