In this article we are going to discuss some important Questions regarding Interface and abstract in C#.
Que 1: Can we define body of Interfaces methods? When to define methods in Interfaces?
Yes. From C# 8.0 it is possible to put method bodies in Interfaces. Before C# 8.0 it is not possible to put method bodies in Interfaces.
Que 2: Can you create an instance of an Abstract class or an Interface?
No. Abstract class and interface purpose is to act as base class via inheritance. There object creation is not possible.
Que 3: Do Interface can have a constructor?
NO. Interface can only be used for inheritance, so constructor is not required.
Que 4: Do abstract class have Constructors in C#?
YES, Abstract class can have constructors. The reason is, when the abstract class is inherited in the derived class, and whenever the object of the derived class is created then FIRST the constructor of the abstract/ base class will be called and then only the constructor of derived class will be called.
Que 5: What is the difference between abstraction and abstract class?
-Abstraction means showing only required things and hide the BACKGROUND
details.
-Abstract class is one of the ways to implement abstraction
Que 6: Can Abstract class be Sealed or Static in C#?
NO. Abstract class are used for inheritance, but sealed and static both will not allow the class to be inherited.
Que 7: Can you declare abstract methods as private in C#?
NO. Abstract methods are only declaration, and they must be implemented in the derive class, therefore they can not be private.
Que 8: Does Abstract class support multiple Inheritance?
NO. Only at maximum one abstract class can be used for inheritance. But multiple interfaces can be used.