Difference between Method Overriding and Method Hiding in C#

CsharpServer Side ProgrammingProgramming

In C# there are two mechanisms for redefining or providing the new implementation of a method of parent class by its child class and these two mechanisms are known as Method overriding and Method hiding. Now on the basis of how method re-implementation is done we can distinguish between both of them.

Following are the important differences between Method Overriding and Method Hiding.

Sr. No.KeyMethod OverridingMethod Hiding
1DefinitionMethod Overriding is a mechanism to achieve polymorphism where the super class and sub class have same methods, including the parameters and signature and, when you call it using the sub class object, the implementation in the subclass is invoked.On other hand Method Hiding can be defined as technique in which user can redefine the method of base or parent class using new keyword which results in hiding the main basic implementation provided by base class of that particular method.
2Access of Parent implementationIn Method Overriding child class can access parent class method implementation.In case of Method Hiding parent class method implementation cannot be accessed through child class reference.
3Modifier UsedFor Method overriding override keyword is being used.In case of Method Hiding new keyword is used to define new implementation in child class.
4Implementation typeIn Method Overriding the implementation type of the method is of object type.However on other hand implementation type of method in Method hiding is of reference type.
5Parent to child referenceIn Method Overriding when parent class reference variable is pointing to the object of the child class, then it will call the overridden method in the child class.On the other hand in Method Hiding, when parent class reference variable is pointing to the object of the child class, then it will call the hidden method in the parent class.
6UsageMethod Overriding only redefines the implementation of the method.Method Hiding can completely redefine the method.
Published on 09-Jun-2020 12:43:11