Geeks Talk

Prepare for your Next Interview




method overloaing?

This is a discussion on method overloaing? within the Java forums, part of the Software Development category; What is the main reason to use method overloading ? I know the concept but i don't know why they use ?...


Go Back   Geeks Talk > Software Development > Java

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 12-20-2006
Contributing Member
 
Join Date: Sep 2006
Location: bangalore, india
Posts: 1,007
Thanks: 0
Thanked 76 Times in 64 Posts
psuresh1982 will become famous soon enough
method overloaing?

What is the main reason to use method overloading ? I know the concept but i don't know why they use ?
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-20-2006
Expert Member
 
Join Date: Sep 2006
Location: Bengalooru (Formerly called Bangalore), India
Posts: 486
Thanks: 2
Thanked 28 Times in 27 Posts
kalayama is on a distinguished road
Re: method overloaing?

Method overloading is very very handy as the same function name can be used for performing the same/similar operation for different data types.

Let us say that you want to write a function to sort arrays. Using method overloading, you can have a single function name (say sort) for sorting any kind of array(May it be string, integer, float, long, double). You just need to define the function so many times. (So many times as the datatypes you want to sort). Once your library is built, the user just needs to give

Code:
sort ( array_name )
and your array is sorted.

If method overloading was not there, you need to have functions like sort_int (For sorting Integer array), sort_float(For sorting Float) etc...

Isn't the use and power of method overloading obvious?
[It was obvious to me as I shifted to OOPS from C. C doesn't have these concepts and I had suffered the lack of function overloading when I was programming with C ]

Hope this helps.

Cheers,
Kalayama
__________________
[COLOR="Blue"][SIZE="2"]"If you are not living on the edge of your life, you are wasting space"[/SIZE][/COLOR]

Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"
Reply With Quote
The Following User Says Thank You to kalayama For This Useful Post:
  #3 (permalink)  
Old 12-21-2006
Contributing Member
 
Join Date: Sep 2006
Location: bangalore, india
Posts: 1,007
Thanks: 0
Thanked 76 Times in 64 Posts
psuresh1982 will become famous soon enough
Re: method overloaing?

Yes its very helpful to me...In my referriing book they mentioned "one name, multiple form". Previously i am not clear about this statement.. Now i can understand....

---------------------
suresh
Reply With Quote
  #4 (permalink)  
Old 08-22-2008
Junior Member
 
Join Date: Aug 2008
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
sjava.438 is on a distinguished road
Re: method overloaing?

Hi,
By using method overloading we can reduce the complexity.
take a example i want to add two numbers of type int , float , char. at this time no need to write different methods. will overload methods for each share same name as add.
Reply With Quote
  #5 (permalink)  
Old 09-05-2008
Junior Member
 
Join Date: Jun 2007
Location: India
Posts: 20
Thanks: 0
Thanked 6 Times in 4 Posts
deeptiagrawal is on a distinguished road
Re: method overloaing?

Method overloading help you to perform same/similar task but with different parameter list. Suppose you are writing a program to calculate the area of figures.
With the help of function overloading you can use the same name Area() with different number and type of parameters. No need to remember the name as Area_Circle(), Area_Rectangle(), Area_Square() etc just write one name Area with different parameters and your problem is solved.
Reply With Quote
  #6 (permalink)  
Old 09-07-2008
Junior Member
 
Join Date: Sep 2008
Location: india
Posts: 9
Thanks: 0
Thanked 1 Time in 1 Post
mkranthikumar.mca is on a distinguished road
Re: method overloaing?

The simple example is to find of absolute value of integer we will use abs() and to find absolute value of float we will use fabs() and to find long absolute value we will use labs.
That means the functionality of all the functions will be same but there is difference in the arguments. If there is change in arguments we have to use different function name.
To avoid that problem in java overloading was introduced. Because even though arguments may have different data types the suitable method will be called depending on parameters.
By using this concept we will overcome naming problem and space problem
Reply With Quote
Reply

  Geeks Talk > Software Development > Java

« java | Static »

Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
Difference between method overriding and overloading nancyphilips OOPS 23 4 Days Ago 03:26 AM
Constructor in place of init() method Lokesh M Java 1 01-31-2008 03:43 PM
Direct input method in BDC Lokesh M SAP R/3 1 03-09-2007 04:15 PM
Remote Method Invocation prakashnemesis Test Cases 1 02-12-2007 02:37 PM
Help me to Know about this Method blenda ASP.NET 1 11-12-2006 03:16 PM


All times are GMT -4. The time now is 05:19 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved