Method Overriding in C#

The Method Overriding is defined as Defining More than One Method with the same Name under different Classes or In Other words we can say that, contain Multiple Methods with the Same Name using the concept of parent and Child Class relationship.
The Method Overriding is the process of re-implementing the method defined in the parent class in the child Class These Methods are defined with the Modifier VIRTUAL in the parent Class and Overridden in the child Class with the Modifier Override.
We can Directly use method Definition of parent class or simply we can consume the method of parent in the child Class. When a Method is defined as VIRTUAL In a class then we are giving an Option to re- Implement the method in the child class or inherited Class or can be consumed directly without the re-implementation in the child Class. These are mainly derived from the Base library – “System” Class.
Example,

Here in This Example,
BaseClass Has Method – “Display” – With no parameter available, and this has been defined with the Virtual modifier, hence the Method is allowed to re – implement the method body in the child class or can be consumed with same method body without re – implementing in the child class.

OverrdingClass à In Our Application, another class has been defined with the Name “Overriding Class” but this class want the same method defined in the parent class – so we have inherited in the child class.
At the Same time, behavior is not as required in the child class, so user has re implemented the method as required by using the modifier Override








Comments

Popular posts from this blog