In C#, when you have a method in a base class that you would like to use in a derived class but with some modifications you are overriding a method.  When overriding a method in a derived class you must have the exact same signature as the method you are going to override in the base class.  In addition, it is good practice to include the virtual keyword in the signature of the base class method that is to be overridden by a derived class method.

Example method in base class:

public virtual string setSpecies()
{<br />&nbsp;&nbsp; &nbsp;return &quot;Mammal&quot;; &nbsp;&nbsp;<br />}

 

Example – overridden method in derived class

public override string setSpecies()
{<br />&nbsp;&nbsp; &nbsp;return &quot;Reptile&quot;;<br />}

 

 

 

« »