Interface vs. Abstract Classes

Today I’m going to talk about the main differences between abstract class and interface.

First of all, we have to remember that they are both essential because in c# it is not possible to have multiple inheritances, so we can inherit only from a parent class, but we can inherit from more interfaces.

Let’s start right away with the first differences between the two.

Interfaces cannot have variables but only properties to define variables while an abstract class can have all kinds of variables.

Also for methods, the situation, in particular, interfaces can have only the method signature while abstract classes don’t have to have only abstract methods but can have already defined methods.

Following these two things we must remember that when we inherit from an interface, we have to implement all the methods and properties that are defined in it in order not to run into errors, while with abstract classes we implement only the methods that we want to override.

Another difference is the access specifier for the functions, interfaces can’t have them and they are always public while abstract classes behave like a normal class.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store