Thursday, January 14, 2016

Abstract Class Vs Interface in C#

In today's blog post, I will be discussing a very common interview question i.e. the difference between abstract class and interfaces in C#.

Abstract Class

Any class declared with abstract keyword becomes an abstract class. They are used  to define a contract but when we want to have some default behavior associated with the hierarchy.


An interface is defined using the interface keyword. Interfaces are used to define a contract and when we do not want to associate any default behavior with the hierarchy of classes.

Abstract Class Vs Interface in C#

So both of them are used to define contract and are important to understand in order for us to use them in our code properly. Let's look at the differences one by one.

Abstract Class can have implementation for some of its members which exists as the default behavior for the hierarchy. The interface can't have implementation for any of it's members. This is the most important difference between the two and guides our choice most of the time when deciding between the two.

The next difference is that interfaces are limited in terms of hierarchy in the sense that an interface  can inherit from interface only. As compared to that, abstract class can inherit from abstract class as well as interface.

Another difference is that abstract class can have fields whereas an interface can not have any fields. Interface can only have methods.

Another really important difference is that a class can inherit from multiple interfaces simultaneously whereas a class cannot inherit from multiple classes at same time.

And lastly, the interface members cannot have access modifiers. Everything is public by default.
Abstract class members can have access modifiers like public, private, etc.


It's one of the most common interview question and still I wonder why so many people get it wrong in their interviews. These differences are important to understand when to use which one. In general, when multiple entities in the system share common behavior then we might use abstract classes. If we just want the entities to follow a contract and not provide any default implementation then we are better with an interface.
For future updates to my weekly blog, please subscribe to my blog via the "Subscribe To Weekly Post" feature at the right and follow me on Twitter. Until then Happy Coding :)


  1. >The interface can't have implementation for any of it's members.

    Though this is true, you can use extension methods to give behaviour to interfaces. So the biggest draw back of interfaces is negated when you take this into consideration.

    The other big drawback not mentioned is that you can't define the constructors of an interface.