Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2009
    Rep Power

    Default What is use of method overloading and overriding

    Method overriding means same method has written in both child and parent classes.overloading means write same method with different signatures.But I want to know what is the use to write to use this type of polymorphism in real time?
    thanks in advance

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Richmond, Virginia
    Blog Entries
    Rep Power


    Overriding comes in handy for when you want to change functionality of some method based on a class. For example, the toString method in the object class doesn't print much useful. With overriding you can change it to print something more useful for different types of classes.

    Overloading is useful to add flexibility to a method. What if you want to create a method that adds two numbers, but it only takes integers, a bit restrictive isn't it? You can overload it to add floats, doubles, etc. There is a lot more useful uses for both.

    I am not sure this isn't you looking for homework answers so I gave you a little, with this you should be able to think of more useful ways to use them.

  3. #3
    kbro3 is offline Member
    Join Date
    Feb 2011
    Rep Power


    A simple example of method overloading in action would be a method that adds numbers. Since you don't know how many numbers you'll need to add, the compiler will call the right method based on signature:

    public int add(int a, int b){

    return a + b;


    public int add(int a, int b, int c){

    return a + b + c;


  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power


    Four posts, four threads started, never once bothered to return to acknowledge the useful responses, let alone thank the volunteers who gave time and effort to help.

    Conclusion: not deserving of help on a forum.


Similar Threads

  1. Overloading or Overriding...
    By chathura87 in forum New To Java
    Replies: 5
    Last Post: 02-22-2011, 02:46 AM
  2. Method Overloading - Doubt
    By vidya lakshman in forum New To Java
    Replies: 4
    Last Post: 02-01-2011, 07:47 AM
  3. Method Overloading Verification
    By lala in forum New To Java
    Replies: 22
    Last Post: 11-30-2010, 06:32 AM
  4. method overloading and arrays.
    By glopez09 in forum New To Java
    Replies: 5
    Last Post: 12-08-2009, 04:02 PM
  5. Method/Operator Overloading
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-01-2007, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts