Home > DeveloperSection > Interviews > what is difference between method overloading and method overriding

Posted on    October-19-2010 12:00 AM

 OOPS OOPS 
Ratings:
 1 Answer(s)
  1231  View(s)
Rate this:

Pushpendra Singh

Total Post:241

Points:1205
Posted on    November-08-2010 1:00 AM

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)
{

}
}



Don't want to miss updates? Please click the below button!

Follow MindStick