The right way to override a method from a base class in a de
The right way to override a method from a base class in a derived class (i.e., making use of the base class method when appropriate in your re-implementation of the method in the derived class) in C#
Solution
Example :-
class Base
{
public virtual void Display()
{
System.Console.WriteLine(\"Base::Display\");
}
}
class Derived : Base
{
public override void Display()
{
System.Console.WriteLine(\"Derived::Display\");
}
}
class Demo
{
public static void Main()
{
Base b;
b = new Base();
b.Display();
b = new Derived();
b.Display();
}
}
Output :-
Base :: Display
Derived :: Display
Explanation :-
In order to override the base class method \"display\"
we make it virtual in base class and use ovveride keyword for the same method in derived class.

