Advertisement



< Prev
Next >



C# Method Overriding





In C#, you can declare a method of a base class with the virtual keyword, which allows its derived class to redefine its definition i.e. when the class with virtual method is inherited.

Hence, in simple words, you can override the definition of base class methods marked with virtual keyword, in any of its derived classes, by a process known as method overriding.

To override the definition of a virtual method of the base class, we must use the override modifier, when the method is being overridden in the derived class.




Use of method overriding


The key benefit to method overriding is that you can alter the behaviour of the method inherited from a base class and define its specification according to the need of the derived class.





Rules to method overloading -












Why method overriding is needed?


Method overriding is mainly used in a situation when we want to create a more specialized version of a generic(general) method inherited from a superclass, within the subclass.



Please share this article -





< Prev
Next >
< C# Method Overloading
C# Call By Value >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement