File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "function overloading" Watch "function overloading" New topic
Author

function overloading

neeni maur
Greenhorn

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
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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

or


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

or


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:


Steve
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
Sheriff

Joined: Oct 13, 2005
Posts: 38515
    
  23
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: function overloading