Interface vs. Abstract Class
Question
What are the differences between an
interfaceand anabstract class?
Short interview answer
An interface defines a contract that unrelated types can implement, and a type can implement multiple interfaces. An abstract class is a base class that can share state, constructors, and implementation, but a class can inherit from only one base class.
Detailed answer
Use an interface for a capability such as ILogger or IComparable<T> that may apply to unrelated types. For example, both FileLogger and DatabaseLogger can implement ILogger while sharing no base implementation. Use an abstract class when derived types belong to one hierarchy and share protected members, fields, constructors, or default behavior: PaymentProcessor can keep common retry configuration while CardProcessor and BankTransferProcessor provide their differing steps. Modern interfaces can provide default members, but they still do not provide instance fields or constructors.