What is the difference between an interface and an abstract class?
Short answer
An abstract class can hold state and shared implementation and supports single inheritance; an interface is a contract a type can implement many of. Use interfaces for capabilities, abstract classes for a shared base.
Advertisement
AModel answer
An abstract class can hold state and shared implementation and supports single inheritance; an interface is a contract a type can implement many of. Use interfaces for capabilities, abstract classes for a shared base.
public interface IPayable { decimal Pay(); }
public abstract class Employee : IPayable { public string Name=""; public abstract decimal Pay(); }Real-world example
IPayable expresses the capability; Employee shares Name across subtypes.