Saturday, April 17, 2021

What is the difference between Abstract Class and Interface in C#?


This is a very important question for interviews at all levels.

Common differences to remember,

  • An abstract class is a half defined class, Interface is fully abstract
  • An abstract class does not provide full abstract implementation but the Interface does
  • Multiple inheritances of an abstract class are not allowed but multiple interfaces are allowed
  • An abstract class can contain a method with implementation and fields but Interfaces are only allowed to declare methods and properties.
  • Access modifiers can be defined in an abstract class but Interface is by default public
  • An abstract class and methods require Abstract keyword to declare whereas in Interface it is Interface
  • In other words, an abstract class does not provide full abstraction but an Interface does

Common points to remember,

  • We can not create an object of both Abstract class and an Interface
  • An abstract class with all abstract member are similar to an Interface declaration

I hope this basic differences and common characteristics help you to understand the basics of both an Abstract class and an Interface.

For more details, you are welcome to visit the dedicated posts for each topic as given below,

Any doubts, confusion? feel free to drop your thoughts. 

No comments:

Post a Comment

C# Interview Prep: 100 Common Questions for 0-3 Years Experience

Common C# Interview Questions  Basics of C# Language: What is C#? C# (pronounced C sharp) is a modern, object-oriented programming language...