Difference between Abstract Class and Interface in C#
Basic difference between abstract Class and Interface is in an abstract class, we can create the functionality and that needs to be implemented by the derived class. The interface allows us to define the functionality or functions but cannot implement that. The derived class extend the interface and implement those functions.
An abstract class is giving an abstraction to real world entities and objects in C#. An Abstract class is never intended to be instantiated directly, means we can not create an object of abstract class. This class must contain at least one abstract method, which is marked by the keyword or modifier abstract in the class definition. The Abstract classes are typically used to define a base class in the class hierarchy.
Interface contains only method declaration. Like a class, Interface can have methods,
properties, events, and indexers as its members. But interfaces will contain only the
declaration of the members. Method definition of Interface will be given in its implementation class which implements the interface implicitly or explicitly.
|It contains both declaration and as well as definition.||It contains only a declaration part.|
|It contain constructor.||It does not contain constructor.|
|It can contain static members.||It does not contain static members.|
|It can contain different types of access modifiers like public, private, protected etc.||Contains public access modifier as because everything in the interface is public by default.|
|The performance of an abstract class is faster.||On other hand the performance of interface is slow because it requires time to search actual method in the corresponding class.|
|A class can only use one abstract class.||A class can use multiple interface.|