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.
Here you can see the functions name are same but parameter type and number of parameters are different.
What is method Overriding?
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.
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 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.
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.
- What is a Class?
- What is an Object?
- Constructors and Destructors
- What Is Inheritance ?
- What are the different types of inheritance ?
- What are Access Modifiers ?
- Why Classes cannot be declared as Protected?
- Can we declare private class in namespace
- Difference between Classes and Structures
- Can we use pointers in C# ?
- Why abstract class can't create instance
- Can you prevent your class from being inherited
- Difference between Early Binding and Late binding
- What is nested class
- What is partial class ?
- What is Virtual Method
- Difference between class and object
- What is Data Encapsulation?
- Object Based Language and OOPs