Abstract Class in C#? example   
  “An abstract is implement that the class is incomplete and can’t be use directly, to use an abstract class other class can derived.”
“An abstract class contains abstract method which can be implemented by the…
v You can’t create instance of a abstract class.
v You can’t override the method of the abstract class in the base class.
v You can’t declare abstract method outside abstract class.
v You can’t declare abstract class as a sealed.
v A class which is derived from the abstract class must override all the method inside the abstract class.
v If a derived class doesn’t implement all of the abstract method in the base class, then the derived class must also be specified by abstract.
v Abstract method is method without any body.
Example:

using System;
abstract class Animal
{
    public abstract void FoodHabits();
}
class Carnivorous:Animal
{
    public override void FoodHabits()
{
    Console.WriteLine("The Carnivorous Animal Eat Only Meat");
}
}
class Herbivorous:Animal
{
    public override void FoodHabits()
    {
        Console.WriteLine("The Harbivorous Animal Eat Only Plants");
    }
}
class Implement
{
    public static void Main()
    {
        Carnivorous cn = new Carnivorous();
        Herbivorous hb = new Herbivorous();
        cn.FoodHabits();
        hb.FoodHabits();
        Console.ReadLine();
    }
}

See the output below…..







SO Friends these are few Blogs that will help you in "Abstract Class in C-sharp" next time i will put some more interesting Blogs thank you..I Hope Help full u... enjoy :) .Krishna Singh



0 comments:

Post a Comment

Rate me

Free Rating Code
 
Top
How to Become Author of TechFusion || write your suggestion and idea on comment box, we try to implement it.