Please give your valuable suggestions and feedback to improve this article in the comments section.


Abstract class definition with example in C#.Net

Abstract Class 

Using Abstract keyword, we can create a class using C#.net. Main purpose of the Abstract class is for inheritance for defining the features of the non abstract and derived classes.

Syntax:
public abstract class IAmAbstract
{
//we will write class members here. 
}

Important points:

  • An abstract class can't be instantiated. 
  • Main purpose of the abstract class is to provide the common definition of the parent class to the multiple child classes. 
  • Abstract classes can have the abstract methods. Abstract methods don't have implementation. So, when ever we extend abstract class we have to implement this abstract method. 
  • When Abstract class is having the virtual method, still we want to use same method we can override the method.

Example Program:


// compile with: /target:library
public class ClassA
{
    public virtual void Work(int i)
    {
        // Original implementation.
    }
}

public abstract class ClassB : ClassA
{
    public abstract override void Work(int i);
}

public class ClassC : ClassB 
{
    public override void DoWork(int i)
    {
        // New implementation.
    }
}

See more OOPS dotnet Interview Questions
See more ASP.NET, C#.NET, Sql Server Interview Questions
Share this post :

Post a Comment

Please give your valiable feedback on this post. You can submit any ASP.NET articals here. We will post that articals in this website by your name.

Note: only a member of this blog may post a comment.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar