Prepare for your Next Interview
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 ?...
|
|||
|
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 ) 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!" |
| The Following User Says Thank You to kalayama For This Useful Post: | ||
|
|||
|
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 |
|
|||
|
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. |
|
|||
|
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. |
|
|||
|
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 |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| 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 |