WHAT IS DIFFERENCE BETWEEN METHOD OVERLOADING AND METHOD OVERRIDING

Amit Singh

Total Post:565

Points:2825
Posted by  Amit Singh
OOPS 
 2112  View(s)
Ratings:
Rate this:
  1. Pushpendra Singh

    Post:241

    Points:1205
    what is difference between method overloading and method overriding

    Method overloading means having two or more methods with the same name but different signatures in the same scope. Compiler automatically select the most appropriate method based on the parameter supplied.

    public class multiplynumber
    {
    public int multiply(int x, int y)
    {
    return x * y;
    }
    public int multiply(int x, int y, int z)
    {
    return x*y*z;
    }
    }

    Method Overriding is achieved when a subclass overrides non-static methods defined in the superclass, following which the new method implementation in the subclass that is executed.
    The new method definition must have the same method signature and return type.
    Clas A
    {
    Virtual void sum (int a)
    {
    }

    }

    Class B:A
    {
    public overrid void sum (int a)
    {

    }
    }


Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!