Write a program of Inheritance in C#
using
System;
namespace
Lab_Assignment
{
class Animal
{
protected string Name;
protected int Age;
public Animal()
{
}
public virtual void Display()
{
}
}
class cat:Animal
{
public override void Display()
{
Name = "Cat";
Age = 4;
Console.WriteLine("Name of
Animal is :{0}", Name);
Console.WriteLine("Age of
Animal is :{0}", Age);
Console.WriteLine("Cat voice
is (Meao Meao)");
}
}
class Lion : Animal
{
public override void Display()
{
Name = "Lion";
Age = 5;
Console.WriteLine("Name of
Animal is :{0}", Name);
Console.WriteLine("Age of
Animal is :{0}", Age);
Console.WriteLine("Lion voice
is (Ror Ror)");
}
}
class Sheep : Animal
{
public override void Display()
{
Name = "Sheep";
Age = 3;
Console.WriteLine("Name of
Animal is :{0}", Name);
Console.WriteLine("Age of
Animal is :{0}", Age);
Console.WriteLine("Sheep voice
is (Mai Mai)");
}
}
class Horse : Animal
{
public override void Display()
{
Name = "Horse";
Age = 6;
Console.WriteLine("Name of
Animal is :{0}", Name);
Console.WriteLine("Age of
Animal is :{0}", Age);
Console.WriteLine("Horse voice
is (Heee Heee)");
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Animals
Names And Specification");
Animal[] animals = new Animal[6];
animals[0] = new cat();
animals[0].Display();
Console.WriteLine("_______________________________________");
animals[1] = new Lion();
animals[1].Display();
Console.WriteLine("_______________________________________");
animals[2] = new Sheep();
animals[2].Display();
Console.WriteLine("_______________________________________");
animals[3] = new Horse();
animals[3].Display();
}
}
}
Comments
Post a Comment