CSharp - Difference between an abstract class and an interface

Introduction

An abstract class can be fully implemented or partially implemented.

An abstract class can have concrete methods, but an interface cannot have concrete methods.

An abstract class can have only one parent class.

An interface can have multiple parent interfaces.

An interface can only extend from other interface(s).

The methods of an interface are public by default.

An abstract class can have other flavors (e.g., private, protected etc.).

In C#, fields are not allowed in an interface.

An abstract class can have fields (both static and non-static with different kind of modifiers).

So, if you write something like this:

interface IMyInterface
{
   int i;//Error:Cannot contain fields
}

You will receive a compiler error.

However, the following code is fine:

abstract class MyAbstractClass
{
   public static int i=10;
   internal int j=45;
}

Related Topic