What is the difference between an interface and an abstract class in C#?
cs-jun-004
Your answer
Answer as you would in a real interview — explain your thinking, not just the conclusion.
Model answer
An interface defines a contract — a set of method and property signatures with no implementation (before default interface members in C# 8). Any class or struct can implement any number of interfaces, giving you multiple-type polymorphism. An abstract class can hold partial implementations, fields, constructors, and state; it can only be inherited once (single inheritance). Choose an interface when you want to define a capability that many unrelated types should share — IDisposable, IComparable. Choose an abstract class when you have shared implementation that subclasses should reuse, and the types are genuinely related by IS-A.
Code example
// Interface: pure contract, multiple implementation
public interface ISerializer
{
string Serialize<T>(T obj);
T Deserialize<T>(string json);
}
// Abstract class: shared implementation
public abstract class Animal
{
public string Name { get; }
protected Animal(string name) => Name = name;
public abstract string Speak(); // must override
public string Describe() => $"{Name} says: {Speak()}"; // shared impl
}
public class Dog : Animal, ISerializer
{
public Dog() : base("Dog") { }
public override string Speak() => "Woof";
public string Serialize<T>(T obj) => System.Text.Json.JsonSerializer.Serialize(obj);
public T Deserialize<T>(string json) => System.Text.Json.JsonSerializer.Deserialize<T>(json);
}
Follow-up
When were default interface methods introduced, and what problem do they solve? Does their existence blur the distinction between interfaces and abstract classes?