I found that lots of people our there are confused between abstract and interface, including me :-). So i formulated this simple table which list most of the differences between them.

Index Abstract Interface
1 Cannot instantiate(not possible to create object of an abstract class) Cannot instantiate. (not possible to create object of an interface)
2 Can have method implementations inside the class Cannot have method implementations, only method signatures
3 Can have access specifiers Cannot have access specifiers (like public,private,protected,internal etc.)
4 Can inherit from a class and one or more interfaces Can only inherit from another interface
5 Can contain data fields

Cannot contain data fields

For ex:

public interface myInterface

{

int myVals; //not possible

}

6

Can contain property implementations.

 

Cannot contain property implementations.

For ex:

public interface myInterface
{

string myProp1
{
get; set;
}
void HelloWorld();
}

7 Can contain constructors and destructors. Cannot contain constructors and destructors.
8 Structure cannot inhert an abstract class. Structure can inherit an interface.
9 Does not support multiple inheritance. Supports multiple inheritence.
10 Derived class doesn’t need to implement all base class methods. Derived class needs to implement all base class methods.

Please refer to it. I hope it was helpful. Please point out if there is been an error. Happy Coding!!!!


Discover more from Cloud Distilled ~ Nithin Mohan

Subscribe to get the latest posts sent to your email.

By Nithin Mohan TK

Technology Enthusiast | .NET Specialist | Blogger | Gadget & Hardware Geek

One thought on “Abstract vs Interface (C#): A Simple Tabular Index”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.