Wednesday, September 17, 2014

C# Programming Tutorial

                         Abstract Class Tutorial in C#

Introduction:   

  • An abstract class is an incomplete and does not instantiated.
  • It only used for base class.In the abstract base class only define the abstract members and methods.
  • Abstract class must implement in derived class.Until it will be a compiler error.         
  • Cannot be implement the abstract members and methods,change the derived class to the abstract class(Put the keyword abstract in derived class).It is not an error.
  • Abstract class cannot be used a sealed type.Because sealed type used for preventing inheritance.Abstract base class must be derived and implement by derived class.So we cannot used sealed type.
  • In derived class using override key word to implement the abstract class method. 
EX:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Abstract
{                                                         
    class Program                            
    {                                         
        static void Main(string[] args)       
        {                                      
            B b = new B();                    
            b.print();                                                     
        }                                     
    }                                        
}                                             
public abstract class A
{
    public abstract void print();  //Abstract class method definition.
}
class B : A
{
    public override void print()   //Abstract class implementations using override key word.
    {
        Console.WriteLine("Abstract Class");
    }

}

OUTPUT:
             
              Abstract Class