An abstract class is an incomplete class because it does not have an implementation for all of its members since they are abstract and an abstract class cannot be sealed.
We all know how to create a class.
To create a class we do the following:
- public class NonAbstractClass {
- }
- public abstract class MyAbstractClass {
- }
Using an abstract keyword
Let's look at an example where I want a method that is an abstract method.
- public abstract class MyAbstractClass {
- public void MyAbstractMethod() {
- }
- }
- public abstract class MyAbstractClass {
- public abstract void MyAbstractMethod() {
- }
- }

The reason is, we can only provide an implementation for the abstract members in a class that inherits the abstract class.
- public abstract class MyAbstractClass {
- public abstract void MyAbstractMethod();
- }
Instance of an abstract class
I told you earlier that abstract classes are incomplete because they do not have an implementation for all of its members since they are abstract and since they are abstract, it doesn't make any sense to be able to create an instance of this class and use those members to do something. That's why you cannot create an instance of an abstract class and they can only be used as a base class for other classes.
In my project, I have another class named “Program” that is a non-abstract class. Now what we will do is, we will inherit our Program class from the abstract class that we have created, in other words MyAbstractClass.
If you look at this program class, it is a non-abstract class because we haven't used an abstract keyword.
- public class Program {
- static void Main(string[] args) {
- }
- }
- public class Program : MyAbstractClass{
- static void Main(string[] args) {
- }
- }

If your program class doesn't wish to provide an implementation, then you can mark your program class as an abstract class.
- public abstract class Program : MyAbstractClass{
- static void Main(string[] args) {
- }
- }
But on the other hand, if you don't want your Program class to be marked as abstract then provide an implementation for all the abstract members and provide an implementation for the abstract members. Use an override keyword for that.
- class Program : MyAbstractClass{
- override space abstractMethod press enter
- class Program : MyAbstractClass{
- public override void MyAbstractMethod() {
- throw new NotImplementedException();
- }
- }
- class Program : MyAbstractClass {
- public override void MyAbstractMethod() {
- Console.WriteLine("my abstract method implementation");
- }
- }
- class Program : MyAbstractClass {
- public override void MyAbstractMethod() {
- Console.WriteLine("my abstract method implementation");
- }
- static void Main(string[] args) {
- Program p = new Program();
- p.MyAbstractMethod();
- }
- }

You can do the same by using a base reference variable pointing to your child class object.
- static void Main(string[] args) {
- MyAbstractClass myAbstract = new Program();
- myAbstract.MyAbstractMethod();
- }

An abstract class cannot be sealed. We have learned, if you want to prevent your class from being inherited by another class then we use a sealed keyword. But if we go by the definition, an abstract class can only be used as a base class and so it cannot be sealed.
- abstract sealed class MyAbstractClass {
- }

An abstract class may contain abstract members but not mandatory.
Here I have an abstract class MyAbstractClass with an abstract member MyAbstractMethod but I can also have a member in the same abstract class MyNonAbstractMethod that is a non-abstract member.
- abstract class MyAbstractClass {
- public abstract void MyAbstractMethod();
- public void MyNonAbstractMethod() {
- Console.WriteLine("my non-abstract method implementation");
- }
- }
Important Note
If a class inherits an abstract class, provide an implementation for all the abstract members inherited from the base abstract class.
If a class does not wish to provide an implementation for all the abstract members inherited from the abstract base class, then the class must be marked as abstract.

Gowtham RajamanickamPosted Mar 18, 2015, 3:38 AM
good show...
Onlymorons onthiswebsitePosted Feb 4, 2015, 7:43 AM
"An abstract class is an incomplete class" Is not true, often it is, but its a bad definition. What makes an abstract class different from a normal class is that they cannot be instantiated. On top of that they can have abstract methods, but this is not a requirement
Stephan OomenPosted Jan 15, 2015, 1:38 AM
You have given a good example how a abstract class behaves, but I am missing a key concept of abstract class like Polymorphism
Md. Raskinur RashidPosted Jan 11, 2015, 4:21 AM
Good lesson!
Manish Kumar ChoudharyPosted Jan 11, 2015, 2:12 AM
Nice one...