Abstract - Virtual - Static - 2017
Virtual
If a value is declared as virtual, a sub class can override the value.
For Example
The inspect method within the Animal class:
public virtual void Inspect()
{
Console.Write(" ID " + ID + " ");
Console.Write("Age " + Age + " ");
Console.Write("LS " + NaturalLifespan + " ");
Console.Write("Pr dth " + Math.Round(ProbabilityOfDeathOtherCauses, 2) + " ");
}
The fox class overrides this:
public override void Inspect()
{
base.Inspect();
Console.Write("Food needed " + FoodUnitsNeeded + " ");
Console.Write("Food eaten " + FoodUnitsConsumedThisPeriod + " ");
Console.Write("Gender " + Gender + " ");
Console.WriteLine();
}
So does the rabbit class:
public override void Inspect()
{
base.Inspect();
Console.Write("Rep rate " + Math.Round(ReproductionRate, 1) + " ");
Console.WriteLine("Gender " + Gender + " ");
}