Wednesday, June 29, 2016

Abstract class


Abstract class


  • Abstract classes are solely for inheritance
  • We can not create object of abstract class
  • Abstract can not be sealed or static
  • Abstract methods can not be private
  • Abstract methods can not have the body
  • Abstract method can not have the modifier virtual (By default it is virtual)
  • Access modifier of the abstract method should be same in both abstract and derived class
  • Abstract member can not be static
Overview in short
Private (No)
Static (No)
Sealed (No)
Virtual (No, by default virtual)



abstract class c# example



abstract class clsSave
{
    abstract public void Save();
}
class DerivedClass: clsSave
{
    // Area method is required to avoid
    // a compile-time error.
    public override void save()
    {
        //write code to save
    }
    static void Main()
    {
        DerivedClass objD= new DerivedClass();
        Console.WriteLine("Performing Save operation", objD.save());
    }
}

No comments:

Post a Comment