C# Abstract Class Example

Here is an example to show how to implement abstract classes in c sharp
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication10
{
    abstract class animal
    {
        public abstract void foodhabits();
    }
    class carnivorous : animal
    {
        public override void foodhabits()
        {
            Console.WriteLine(“The carnivrous animal eat only meat”);
        }
    }
    class herbivorous : animal
    {
        public override void foodhabits()
        {
            Console.WriteLine(“the HB animals eat only plants”);
        }
    }
    class implement
    {
        public static void Main()
        {
            carnivorous cn = new carnivorous();
            herbivorous hb = new herbivorous();
            cn.foodhabits();
            hb.foodhabits();
            Console.ReadLine();
        }
    }
}
       

Add Comment