Question: C# program help Task Description public abstract class Animal { public string Name { get; set; } public abstract void MakeSound ( ) ; public
C# program help
Task Description public abstract class Animal
public string Name get; set;
public abstract void MakeSound;
public virtual void Eat
Console.WriteLineThis animal eats food.";
Example derived class
public class Bird : Animal
public override void MakeSound
Console.WriteLineChirp;
public override void Eat
Console.WriteLineThis bird eats seeds.";
Main method
static void Mainstring args
List
You are tasked with creating a program that simulates basic behaviors of
different types of animals in a zoo. Your program should include a base class
named Animal and at least three derived classes such as Bird, Mammal, and
Reptile. Each derived class should override a common method to exhibit
unique behaviors.
Step : Create the Base Class
Define an abstract base class Animal with the following features:
A property Name of type string.
An abstract method MakeSound that returns void. This method will be
overridden in derived classes to print the sound the animal makes.
A virtual method Eat that prints a general message about eating habits,
eg "This animal eats food."
Step : Create Derived Classes
Create three derived classes that inherit from Animal:
Override MakeSound For example to print a birdspecific sound, eg
"Chirp".
Optionally, override Eat to print a birdspecific eating habit, eg "This
bird eats seeds."
Step : Demonstrate Polymorphism
In your Main method, demonstrate polymorphism by:
Creating an array or list of Animal objects and populating it with
instances of Bird, Mammal, and Reptile.
Iterating over the collection and calling both MakeSound and Eat on
each Animal object. Observe how the correct method is called based on
the actual object type, not the variable type.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
