This is a detailed analysis of Abstract classes and methods in C# with some concrete examples.
The keyword abstract can be used with both classes and methods in C# to declare them as abstract.
The classes, which we can't initialize, are known as abstract classes. They provide only partial implementations. But another class can inherit from an abstract class and can create their instances.
For example, an abstract class with a non-abstract method.
An abstract class can contain abstract and non-abstract methods. When a class inherits from an abstract, the derived class must implement all the abstract methods declared in the base class.
An abstract method is a method without any method body. They are implicitly virtual in C#.
But by declaring the derived class also abstract, we can avoid the implementation of all or certain abstract methods. This is what is known as partial implementation of an abstract class.
In C#, an abstract class can inherit from another non-abstract class. In addition to the methods it inherited from the base class, it is possible to add new abstract and non-abstract methods as showing below.
An abstract class can also implement from an interface. In this case we must provide method body for all methods it implemented from the interface.
We can't use the keyword abstract along with sealed in C#, since a sealed class can't be abstract.
The abstract methods are implicitly virtual and hence they can't mark explicitly virtual in C#.
For example