Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

What is the difference between abstract class and interface in C#

In this article, I will answer from one of the most frequently asked C# Interview Questions: what is the difference between Abstract Class and interface in C#.

  • Keep reading on How to Convert JSON to Datatable in C#

Difference between Interface and Abstract Class

Abstract Class Interface
  • An abstract class contains at least one abstract member and others, non-abstract members. Like a simple class, an abstract class can have data members and member functions
  • An interface has only the member’s declaration or signature and implicitly every member of an interface is public and abstract. It contains only properties, indexers, methods, delegates and events signature
  • An abstract class contains at least one abstract member and others, non-abstract members. Like a simple class, an abstract class can have data members and member functions
  • It cannot contains constants members, constructors, destructors, instance variables, static members or nested interfaces.
  • It can have field members.
  • It cannot have field members.
  • It can have public, protected and private members.
  • It can have only public members.
  • It can have public, protected and private members.
  • Methods have the only declaration.
  • It provides partial abstraction.
  • It provides the full abstraction
  • Only static constants are possible.
  • Static and Instance constants are possible.
  • It does not support multiple inheritances and so a class can inherit only one abstract class.
  • It supports multiple inheritances and so a class can inherit more than one interface.
  • Use an abstract class when you need to create multiple versions of your component and to provide default behaviors as well as common behaviors that multiple derived classes can share and override.
  • Use an interface when you need to provide a common functionality to unrelated classes and to create loosely coupled components, easily maintainable and pluggable components because the implementation of an interface is separated from itself.

Reference: Stack Overflow

Conclusion

I hope you liked this article on what is the difference between an abstract class and an interface. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

The post What is the difference between Abstract Class and interface in C# appeared first on DotNetTec.



This post first appeared on Asp Dot Net Tricks And Tips, Dot Net Coding Tips, Google Maps API Developer, please read the originial post: here

Share the post

What is the difference between abstract class and interface in C#

×

Subscribe to Asp Dot Net Tricks And Tips, Dot Net Coding Tips, Google Maps Api Developer

Get updates delivered right to your inbox!

Thank you for your subscription

×