Abstract classes
Abstract classes allow to a developer to define different functionalities and to use subclasses in order to either override or implement them. Abstract classes have to have one abstract method at minimum. The keyword abstract
is used to define the class and method as abstract.
Some of the other properties of abstract classes are:
- You can only inherit one abstract class.
- An abstract class may have class members that are static.
- You can have constructors.
- You can have different access modifiers (e.g. public, private, protected).
Interfaces
Interfaces on the other hand, allows a developer to declare, but not define methods. In addition to methods, interfaces can also contain events and properties.
NOTE: Starting in C# 8.0 methods are allowed to be defined in interfaces.
Some of the other properties of interfaces are:
- You can implement multiple interfaces.
- You cannot have class members that are static.
- You cannot have a constructor.
- You may only have public access modifiers since what is contained in an interface must be public.