Home   Cover Cover Cover Cover
 

Abstract Classes

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

Answer: Both abstract classes and interfaces are "prototypes" for future subtypes. Interfaces are fully abstract, i.e. their methods, properties and indexers are only defined by their signatures but do not contain code. In contrast to that, abstract classes can contain also methods, properties and indexers with code.

A class can inherit from just a single base class but it can implement any number of interfaces. With interfaces one can make a class compatible with several other types.

Whereas (abstract) classes are used for code inheritance (subclassing), interfaces are used for type inheritance (subtyping).