What is the abstract class ?

This is one of the frequently asked questions in interview. I have faced this question in almost in all interviews. So let’s understand what is abstract class?

Abstract class is the class which one cannot be instantiated. This means we canot create object of this class like general class. To use it, we need to inherit it. It contains the abstract keyword.

In abstract class, we can define
1. Normal Property
2. Abstract Property
3. Normal Method
4. Abstract Method
5. Virtual method.

Now let see this concept with example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Class1
/// </summary>
public abstract class Class1
    public virtual string SayHello()
        return "Hello from virual method";

    public string sayHello2()
        return "I m from SayHello Method";

    public abstract string SayHello1();


Note: Here i have created the abstract class which contain Normal method,abstract method and Virtual method.

Now we will inherit this class in class2 like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Class2
/// </summary>
public class Class2:Class1
    public override string SayHello()
        return "This is the orveride message using virtual method";

    public override string SayHello1()
        return "This is the orveride message using abstract message";


Note: in the above code i have override the virtual and abstract method. So if virtual or abstract keyword is there then we have to must override it.

Now we will call this method in default.cs page like this on button click event

 protected void Button1_Click(object sender, EventArgs e)
         Class2 obj = new Class2();

Now compile the code, we will get output like this


When to use abstract Class?

We can use this class in this senario

1. If we have created some class and we want to modify some methods with new feature and we have to use somewhere then we can use abstract class

2. If we are developing some product type project, where we have to keep on adding new features in coming days then we can use abstract class.

Note: This is all my understanding my abstract class, if you feel i missing some important point then let me know. You are always welcome.


7 thoughts on “What is the abstract class ?

  1. vinoth April 29, 2013 / 5:27 am

    nice expl…

  2. Delila June 10, 2014 / 7:13 am

    Veгy goοd article. I absolutely aρpreciate this
    website. Stick ѡith it!

  3. Penny June 16, 2014 / 6:32 pm

    Hі it’s me, I am also visitjng this web page daily, this web page
    iss tгuly ɡood and the visittors ɑге in fact sharing nice

  4. irwin.willason June 18, 2014 / 11:31 am

    I amm rreally loving thе theme/design ߋf yοur weblog.
    Dօ ʏou ever run іnto any web browser compatibility issues?
    А handful of my blog visitors have complained ɑbout my site not operating correctly іn Explorer Ьut lօoks grеat in Firefox.
    Ɗo you hɑve any solutions to Һelp fix this issue?

  5. Kendra June 19, 2014 / 12:30 am

    This iss the perfect blog forr anyone who wоuld like to find оut aboսt this topic.

    Yoou realize a աhole lot іts almost hard tо argue ѡith yօu (not tɦɑt I personally wijll neеd to…HaHa).
    Yoս defіnitely put a brand new spin on a subject wɦich has been discussed
    for decades. Wonderful stuff, justt wonderful!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.