Home > .NET > Method Override vs Method Overload

Method Override vs Method Overload

Some people might get confused between method overriding and method overloading, here i will explain the differences between these two methods and how each one of them is used:

Method Overriding means that you have 2 methods in 2 different classes with the same name, same parameters (signatures) but with different implementations in each class, mostly this happen between a base (abstract) class and derived class. Here is an example for method overriding:

Base Class:

Class Animal

protected string Name;

public string WhatAmI()

{

return “I am an animal”;

}

Derived Class:

Class Dog: Animal

public string WhatAmI()

{

return “I am a dog”;

}

Method Overloading means that you have 2 methods in the same class with the same name but different parameters (signatures), example for method overloading:

class Calculations
{
public static int Add(int number1, int number2)
{
return number1 + number2 ;
}

public static int Add(int number1, int number2, int number3)
{
return number1 + number2 + number3;
}
}

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: