C# Abstract Class and Interface Difference

In previous article you have learned about Interface and Abstract class in C#.

Now you learn the difference between abstract class and interface in C#.

Difference between Interface and Abstract Class

Here are some of the key differences between interface and abstract class in C#.

Abstract Class in C#
Interface in C#
Abstract class does not support multiple inheritance
Interface support multiple inheritance
Abstract can have constructors
Interface does not contain constructor
Abstract class can have any type of access modifiers; also can contain non abstract property and methods
Interface cannot have any access modifiers, by default all are public and must be implemented in derived class
In Abstract class, We can have any implementation of non abstract methods
We cannot have any implementation in Interface, it contain only declaration
An abstract class can have fields and constrants defined
No fields can be defined in interfaces

Abstract class declaration

Here we define one abstract class with some properties and methods.

public abstract class CarBaseClass
{
public string Color { get; set; }
abstract bool Start(); //Abstract cannot be private
public abstract bool Start();
bool Stop(); //either have body implementation or have abstract declaration
     bool Stop()
        {
            return true;
        }
}

Things to notice in above abstract class declaration

  • Any abstract declaration must have a public access modifier, Abstract cannot be private
  • We can have non abstract property/ method
  • If we don’t define something as abstract, then we must have implementation (body)
interface declaration

Here is an example of how you can declare c# interface

public interface ICar
{
string Color { get; set; }
public bool Start(); //can't specify access modifier
bool Start();
void Stop()
{ } // can’t have implementation, only declaration
        void Stop();
    }

Things to notice in above interface declaration

  • We can't specify any access modifier
  • can’t have any body implementation, only declaration
  • by default all members are override able, implementation must

You should read following tutorials to understand differences between C# abstract class and interface.

 
C# Interface and Abstract Class Comparison
Other Online Tutorial
C# .net Interview Questions Answers

.Net C# Examples | Join .Net C# Course