Results 1 to 6 of 6

Thread: method overloaing?

  1. #1
    Contributing Member
    Join Date
    Sep 2006
    Answers
    962

    method overloaing?

    What is the main reason to use method overloading ? I know the concept but i don't know why they use ?


  2. #2
    Expert Member
    Join Date
    Sep 2006
    Answers
    477

    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!"

  3. #3
    Contributing Member
    Join Date
    Sep 2006
    Answers
    962

    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


  4. #4
    Junior Member
    Join Date
    Aug 2008
    Answers
    15

    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.


  5. #5
    Junior Member
    Join Date
    Jun 2007
    Answers
    20

    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.


  6. #6

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact