Difference Between Abstract class and Interface in C#
Abstract Class
An abstract class is one that is intended only to be a base class of other classes. The ‘abstract’ modifier is used to make a class abstract. An abstract modifier indicates that there is some missing implementation that needs to be implemented in the class derived from it. The abstract class can have abstract and non-abstract members. An abstract class should have at least one abstract method, otherwise, there is no use of declaring that class as ‘abstract.’
Example of Abstract Class in C#:
As shown in the above example, the abstract method ‘Area’ inside the MyCircle class is overridden in the derived class MyArea.
Interface
An interface contains only the declaration of members including methods, properties, events or indexers. It doesn’t contain the implementation of these members. A class or struct implements the interface, must provide the definition of methods declared in the interface. That means an interface provides a standard structure that the derived class needs to follow.
Example of an Interface in C#:
As shown in the above example the interface MyData has two method declaration getdata() and showdata(). The class NameData who is implementing this interface should give the definition of methods declared in the MyData interface.
Difference Between Abstract class and Interface
ncG1vNJzZmijla6xqrLFnqmeppOawG%2BvzqZmnaGWm7Kzsc2cnGaalanEprHNZpibq6SnrqTAjJyjmqujYq6vsIyipa2dopuupLGNoaumpA%3D%3D