Method Overriding is a technique that allows the invoking of functions from another class (base class) in the derived class. Creating a method in the derived class with the same signature as a method in the base class is called Method Overriding.
In simple words, Overriding is a feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super-classes or parent classes. When a method in a subclass has the same name, same parameters or signature and the same return type(or sub-type) as a method in its super-class, then the method in the subclass is said to override the method in the super-class.
My new parent class.. ! My new child class.. !
In Method Hiding, you can hide the implementation of the methods of a base class from the derived class using the new keyword. Or in other words, in method hiding, you can redefine the method of the base class in the derived class by using the new keyword.
This is my child class.
Method Overriding Vs Method Hiding
|Method overriding||Method hiding|
|In method overriding, you need to define the method of a parent class as a virtual method using virtual keyword and the method of child class as an overridden method using override keyword.||In method hiding, you just simply create a method in a parent class and in child class you need to define that method using new keyword.|
|It only redefines the implementation of the method.||In method hiding, you can completely redefine the method.|
|Here overriding is an object type.||Here hiding is a reference type.|
|If you do not use override keyword, then the compiler will not override the method. Instead of the overriding compiler will hide the method.||If you do not use the new keyword, then the compiler will automatically hide the method of the base class.|
|In method overriding, when base class reference variable pointing to the object of the derived class, then it will call the overridden method in the derived class.||In the method hiding, when base class reference variable pointing to the object of the derived class, then it will call the hidden method in the base class.|
- Method Hiding in C#
- C# | Method Overriding
- Difference between SortedList and SortedDictionary in C#
- Difference between Managed and Unmanaged code in .NET
- C# | Difference between Static Constructors and Non-Static Constructors
- Difference between Class and Structure in C#
- Difference between Abstract Class and Interface in C#
- Difference between Ref and Out keywords in C#
- Difference between Python and C#
- Difference between System Level Exception and Application Level Exception in C#
- Difference between readonly and const keyword in C#
- Difference between Hashtable and Dictionary in C#
- Difference between var and dynamic in C#
- Difference between Boxing and Unboxing in C#
- Difference between C and C#
- Difference between Console.Write and Console.WriteLine in C#
- Difference between Console.Read and Console.ReadLine in C#
- Difference between byte and sbyte in C#
- Difference between Int64 and UInt64 in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.