This Article summarizes the following points written by Akhil Mittal :
- In C#, We can equate an object of a base class to a derived class but not vice versa.
- The override modifier is needed as the derived class methods will get first priority and be called upon.
- These modifiers like new and override can only be used if the method in the base class is a virtual method. Virtual means that the base class is granting us permission to invoke the method from the derived class and not the base class. But, we have to add the modifier override if our derived class method has to be called.
- If the base class object declared the method virtual and the derived class used the modifier override, the derived class method will get called. Otherwise, the base class method will get executed. Therefore for virtual methods, the data type created is decided at run time only.
- All the methods not marked with virtual are non virtual, and the method to be called is decided at compile time, depending upon the static data type of the object.
- An override method is a method that has the override modifier included on it. This introduces a new implementation of a method. We can’t use the modifiers such as new, static or virtual along with override. But abstract is permitted.
Hope this will help !!!