From an interviewer's point of view, method overloading and method overriding and the difference between them is an important concept.
Thus, let's understand it.
What is method overloading?
Creating more than one method or a function that has a same name but different signatures or parameters in the same class is called method overloading.
Key points
- Method overloading is also called early binding or compile time polymorphism or static binding.
- The compiler automatically calls the required method or the function by checking number of parameters and their type, which are passed into that method.
- If the number of parameters and type doesn't match by any method signatures, then it will give the compile time error.
- We can achive method overloading by changing the number of parameters used or by using different types of parameters or by changing the order of parameters
Example
using System;
using System.Collections.Generic;
using System.Text;
namespace MethodOverloadingDemo
{
class Calculator
{
// Two int type parameters method
public int Add(int x, int y)
{
return x + y;
}
// Three int type parameters method
public int Add(int x, int y, int z)
{
return x + y + z;
}
// Two float type parameters method
public float Add(float x, float y)
{
return x + y;
}
// Three float type parameters method
public float Add(float x, float y, float z)
{
return x + y + z;
}
}
class CalculatorDemo
{
public static void Main(string[] args)
{
Calculator calculator = new Calculator();
// Calling the overloaded methods
int result1 = calculator.Add(10, 20);
int result2 = calculator.Add(10, 20, 30);
float result3 = calculator.Add(10.5f, 20.3f);
float result4 = calculator.Add(10.5f, 20.3f, 30.7f);
// Displaying the results
Console.WriteLine("Result of adding two integers: " + result1);
Console.WriteLine("Result of adding three integers: " + result2);
Console.WriteLine("Result of adding two floats: " + result3);
Console.WriteLine("Result of adding three floats: " + result4);
Console.ReadLine();
}
}
}
Output

What is method overriding?
Creating a method in the derived class with same signature as a method in the base class is called method overriding
or
Method overriding means having two methods with the same name and same signature, one method in the base class and the other method in the derived class.
Key points

Dinesh KumarPosted Jan 25, 2022, 5:37 AM
Very simple and clear explanation.
Ajay KrishPosted Jul 12, 2021, 6:24 PM
Thankyou so much its crisp and clear!!
Kalyan KumarPosted Feb 8, 2019, 3:18 AM
Very simple and clear explanation.