First, we will create a base class in C#. Then we will use simple inheritance to create subclasses and specialize behavior. We will override methods and overload comparison operators to be able to compare different instances of a specific class and its subclasses. We will take advantage of this polymorphism.
Now it is time to code all the classes in C#. The following lines show the code for the Animal
abstract class in C#. The class declaration doesn't specify a base class; therefore, this class inherits from Object
, specifically System.Object
. System.Object
is the base class for all the classes included in .NET Framework. The usage of the abstract
keyword before class
makes this class an abstract class that we cannot use to create instances:
public abstract class Animal { protected virtual int NumberOfLegs { get { return 0; } } protected virtual int PairsOfEyes { get { return 0; } } public int Age...