Home   Cover Cover Cover Cover

Abstract classes and interfaces

Question: What is the difference between an abstract class and an interface.

Answer: Both abstract classes and interfaces are "type templates", defining the API of all classes that are derived from them. Interfaces are purely abstract classes, i.e. they contain just signatures of methods, properties and indexers but no code. Abstract classes, on the other hand, can also contain methods, properties and indexers with code. A class can inherit from only one (abstract) class but may implement any number of interfaces. Iterfaces are useful for making a class compatible with multiple other types. While (abstract) classes support code inheritance interfaces support type inheritance.