Back to results for “OOP & Classes”
C# › Interfaces & Abstract Classes

What is the difference between an interface and an abstract class in C#, and when should you choose one over the other?

Beginner

Answer

An interface defines a pure contract (historically method signatures only, though default interface methods exist since C# 8) with no fields or constructors, and a class can implement any number of interfaces simultaneously -- an abstract class can mix abstract (unimplemented) and concrete (implemented) members, can hold fields, properties, and constructors, and provides genuinely shared behavior to its subclasses, but a class can inherit from only one. Use an interface to enforce a capability across otherwise-unrelated classes (like IComparable), and an abstract class when a family of closely related classes should share real, common implementation.
interface IAnimal { void MakeSound(); } // pure contract, no implementation

abstract class Animal {
    public abstract void MakeSound();       // must be implemented by subclasses
    public void Sleep() => Console.WriteLine("Sleeping..."); // shared, concrete behavior
}

class Dog : Animal, IAnimal {
    public override void MakeSound() => Console.WriteLine("Bark!");
}
Real-world example A shape-drawing library defines an IDrawable interface implemented by many unrelated classes (Circle, Chart, Icon), while a closely-related Shape abstract class provides shared Area()/Perimeter() scaffolding specifically for its own geometric subclasses, illustrating both tools used for their distinct, complementary purposes in the same codebase.

Common follow-ups: How do default interface methods (C# 8+) blur this traditional distinction?;What specifically breaks if two interfaces a class implements both declare conflicting default methods?