Introduction
Nowadays, in an interview, no one asks direct questions; rather, they will give you a scenario and ask the solution for the same. And almost always there is one common question that you encounter in almost all interviews: "Where will you use Interface and Abstract class?" The interviewer will give one scenario and ask in this scenario if you will go for Abstract class or Interface and why.
My idea is to give readers an understanding of where to use Interface and Abstract classes but also to give an understanding in detail as well. Because both the concepts are very important.
Abstract Class in C#
The purpose of an abstract class is to provide the default functionality for its base class. You need to put the abstract keyword ahead of class to define it as an Abstract Class, as mentioned below,
publicabstractclassAbstractCar
{
}You can have both abstract and non-abstract methods in the Abstract Class. Generally, we use the abstract class as a base class. But you need to implement all the abstract methods in the derived class by using the override keyword. You can’t create an object of Abstract Class. An abstract class can never support multiple inheritances.
Example

Now we move on and see a few important things about “Abstract Class,” let’s take it one by one.
- We will try to create an object of Abstract Class and see what happens.

So that means we can’t create an object of Abstract Class. - Interface will not provide any access specifier to the abstract method.

It means in the abstract class, abstract methods are not public by default; it's private by default. The access modifier of the abstract method should be the same in both the abstract class and in its derived class. If you declare an abstract method as protected, it should be protected in its derived class. Otherwise, the compiler will raise an error. - Like interface will not provide any access specifier to the abstract method.

We can define Delegates, Properties, etc. in Abstract Class. - Abstract Properties


- You need to implement all the abstract methods in a derived class,

I got the above error because I have not implemented all the methods in the derived class. So it’s mandatory to implement all the abstract methods and properties in the derived class.
Conclusion
I hope this article helps you to explore all the possibilities of Abstract Class. In case not, please drop me a note, and I will explore it further. In the second article, I will talk about Interface and will give more focus on where to use it.


DeepanPosted Nov 22, 2016, 9:03 AM EST
Easy to understand the basics of abstract class
Mohammad KhalidPosted Jul 13, 2016, 11:48 PM EDT
Hi Nishant, Can you please make point number 2 more clear to understand. I think that point need more attention.
SubashPosted Jul 4, 2016, 4:41 AM EDT
Thanks to Give the clear view of abstract Class
Nishant MittalPosted Jul 3, 2016, 8:37 PM EDT
Thanks all
kalu singh raoPosted Jun 30, 2016, 10:01 PM EDT
Nice...
Rahul Pushpendu BhaskarPosted Jun 30, 2016, 5:00 AM EDT
Good...!
Biplab BiswasPosted Jun 24, 2016, 4:35 AM EDT
Nice Article.
Humayun Kabir MamunPosted Jun 18, 2016, 7:45 AM EDT
Nice...
RajaPosted Jun 15, 2016, 2:59 AM EDT
Good One..
Asad AliPosted Jun 9, 2016, 4:59 AM EDT
Good one
soundappan arumugamPosted Jun 5, 2016, 8:24 PM EDT
good
Ravi SPosted Jun 5, 2016, 12:25 AM EDT
Nice Article
Nishant MittalPosted Jun 4, 2016, 10:48 PM EDT
Thanks for the input guys ...will share all the required details in the next artical ..asap...
Rahul Pratap SinghPosted Jun 4, 2016, 9:43 AM EDT
you shared nice technical details of abstract class however you should also share some conceptual details of same.
Ivan GalabovPosted Jun 4, 2016, 12:54 AM EDT
if you need to make changes to interface once released , think again what will happen if MS make changes to IEnumerable<T>. So in general if you need to extend some interface functionality do use abstract class . Never touch interface :)
Asutosha SarangiPosted Jun 3, 2016, 12:14 PM EDT
if you can explain a scenario where to use and why use will appreciate
Ahmed Abd EllatifPosted Jun 3, 2016, 10:50 AM EDT
Nice Article Thanks
Anil Kumar MurmuPosted Jun 3, 2016, 9:30 AM EDT
Awaiting for the next article about interface
Syed Talha ShamimPosted Jun 3, 2016, 7:11 AM EDT
nice
Vignesh ManiTOP 100Posted Jun 3, 2016, 5:32 AM EDT
NIce
Nishant MittalPosted Jun 2, 2016, 10:37 PM EDT
Thanks for reading
sameer shaikhPosted Jun 2, 2016, 10:31 PM EDT
thanks, your article is very helpful to me