0

From what I understand, an abstract class provides a framework of members with no body and enables its subclasses to each implements its own members. But a class cannot inherit from more than one base class and an interface solves that problem by enabling classes to implement as many interfaces as needed.

So what's the purpose of having abstract classes when we can always use interfaces to do the same thing?

Thank you so much in advance!

1 Answers1

2

An abstract class allows you to create functionality that subclasses can implement or override. An interface only allows you to define functionality, not implement it. And whereas a class can extend only one abstract class, it can take advantage of multiple interfaces.

Source : https://www.infoworld.com/article/2928719/when-to-use-an-abstract-class-vs-interface-in-csharp.html#:~:text=The%20short%20answer%3A%20An%20abstract,take%20advantage%20of%20multiple%20interfaces.

Jonas W
  • 3,200
  • 1
  • 31
  • 44
  • 2
    Side note, c# now has "default implementation" for interfaces, which, I personally am not a fan of. – gunr2171 Mar 10 '22 at 19:39