What is the need of Method Overloading and Overriding?

Discussion in 'Java' started by Amod Nazirkar, Oct 7, 2021.

  1. Amod Nazirkar

    Amod Nazirkar New Member

    Joined:
    Sep 28, 2021
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    Hello,

    I really can't seem to understand why method overloading and overriding is needed in java?
    I have read some article regarding this but not able to catch why it's needed practically?

    I am not clear with this topic.

    Any practical example will be appreciated.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,358
    Likes Received:
    383
    Trophy Points:
    83
    Both are a lot different.

    Method overloading is performed within class. So you have two functions that has different set of parameters. Sum is a good example which takes integers as parameter and float as parameter.

    Method overriding occurs in inheritance relationship classes. Sum is already provided as the basic functionality in the parent class but you want to be dealing with it differently in the child class.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice