Free Web Development Online Tutorials, Learn to Code
Learn C# programming Language, Free C# Tutorial for Beginners, C# Development Guide

Abstract Class and Interface Difference in C#

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

Now you lean the difference between abstract class and interface

Difference 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
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
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
 

Difference between Interface and Abstract Class in C#
Other Online Tutorial

C# .net Interview Questions Answers