This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

function overloading

 
neeni maur
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ny 1 can tell me why we use methode or constuctor overloading??
dose it related in terms of memory ???
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49789
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic