Method Overloading and Method Overriding

What is method overloading?

When two or more methods (functions) in the same Class have the same name but different parameters is called method overloading.

Class myClass { int Func(int x) { } int Func(string s) { } int Func(int x,string s) { } }

Here you can see the functions name are same but parameter type and number of parameters are different.

What is method Overriding?

How is method overriding different from method overloading? C# VB.Net

When two or more methods (functions) have the exact same method name, return type, number of parameters, and types of parameters as the method in the parent class is called method Overriding.

class parentClass { public virtual void Disp(int i) { System.Console.WriteLine("parentClass Display" + i); } } class childClass : parentClass { public override void Disp(int i) { System.Console.WriteLine("childClass Display" + i); } }

Here you can see the method name, parameter and return type are same but one method is in the parent class and another one in the child class.

Difference between method overloading and method overriding

Method Overloading versus Overriding C# VB.Net Interview questions and answers

Method overloading happens in the same class shares the same method name but each method should have different number of parameters or parameters having different types and order. But in method overriding derived class have the same method with same name and exactly the same number and type of parameters and same return type as a parent class.

Method Overloading happens at compile time while Overriding happens at runtime. In method overloading, method call to its definition has happens at compile time while in method overriding, method call to its definition happens at runtime. More about..... Static binding and dynamic binding

In method Overloading, two or more methods shares the same name in the same class but having different signature while in method overriding, method of parent class is re-defined in the inherited class having same signature.

What are method overloading and method overriding? C# VB.Net

In the case of performance, method overloading gives better performance when compared to overriding because the binding of overridden methods is being done at runtime.

Static binding is happens when method overloaded while dynamic binding happens when method overriding.

Method overloading add or extend more to the method functionality while method overloading is to change the existing functionality of the method

Static methods can be overloaded, that means a class can have more than one static method of same name. But static methods cannot be overridden, even if you declare a same static method in derived class it has nothing to do with the same method of base class.