Labels

slider

Recent

Navigation

Abstraction class in c#

Abstraction class in c#, Interface vs Abstraction class in c#, Abstraction Class in opps, abstract class in c#, abstract class in c# with example, multiple inheritance in c#

Introduction

Abstraction class is a special class that can't be instantiated. Abstraction class is used in ASP.net (c#) as a result of ASP.net has not multiple inheritances thus we will use abstraction classes as an alternative. Abstraction is inheritable through sub classes, functions, forms etc.  It's alternate to use multiple inheritances in ASP.net. Abstract will use its completely different modifiers specifies however in abstraction class this feature isn't enclosed in interface class. Abstraction class is quicker than interface class. Abstraction have implementation in class also. If we have to use common behaviour in our class then abstract class is better option. We can define abstract class with keyword Abstract class. If you are planning smaller units then use interface class if you use design large units of functions then use abstract class.

abstrac Class in C#


public abstract class TestClass
{
    // Class members can define here.
}
Abstract class can also defines abstract methods also. I have given very good example as given below.
public abstract class TestClass
{
    public abstract void DoTestwork(int j);
}

Abstract class have not implementation. Abstract class can override its methods from base class. When a abstract class inherits methods from its base class, abstract class can overrides its virtual methods class methods. I have provided a very good example for the same.

public class Test
{
    public virtual void DoSampleMethod(int j)
    {
        // Original implementation.
    }
}

public abstract class TestNew : Test
{
    public abstract override void DoWork(int i);
}

public class Funny : TestNew
{
    public override void DoSampleMethod(int j)
    {
        // New implementation.
    }
}

Summary

Explained with example Abstraction class in c#. I have already explained in detail Interface Class, difference between Interface and Abstraction Class and What is Boxing and Unboxing in ASP.Net with example.
Share

Anjan kant

Outstanding journey in Microsoft Technologies (ASP.Net, C#, SQL Programming, WPF, Silverlight, WCF etc.), client side technologies AngularJS, KnockoutJS, Javascript, Ajax Calls, Json and Hybrid apps etc. I love to devote free time in writing, blogging, social networking and adventurous life

Post A Comment:

0 comments: