Differences between interface and abstract class in c#

In this article, I have explained the difference between an Abstract Class and an Interface in C#.
  • 7770

Introduction

It is little confusing when we are discussing about  an abstract class and interface in C#. Some similarities and differences between an interface and an abstract class are following.

Table

Feature Interface Abstract class
Multiple inheritance Interface can implement multiple inheritance It can not
Default implementation An interface has no implementation

An abstract class can provide complete, default code and/or just the details that have to be overridden.

Access Modfiers All interfaces are  by default public and abstract An abstract class can contain access modifiers
Speed Requires more time to find the actual method in the corresponding classes. Fast
Homogeneity If various implementations only share method signatures then it is better to use Interfaces. If various implementations are of the same kind and use common behaviour or status then abstract class is better to use.
Fields and Constants No fields can be defined in interfaces An abstract class can have fields and constrants defined
© 2020 DotNetHeaven. All rights reserved.