An abstract class is one that contains a single or multiple abstract methods. It is also called an abstract base class or ABC sometimes. To elaborate, an abstract method, as we all know, is a method that is declared, but has no implementation. Abstract classes may not be instantiated. They also require subclasses, which in turn provide the implementation for the abstract methods. We can understand this better through an example.
Assume that we are creating a model based on the walking styles of all animals. Different animals have different ways of walking, and some also have some unique features they exhibit during walking. However, there are some features that are common to all animals while they walk. So we create a class hierarchy, at the base of which is the base class Animal. The things that animals do uniquely while walking can be categorized as abstract methods. The implementation for these methods would be provided by the different subclasses that exist under animal – e.g., cow, snake, goat, man, etc.
Basically, abstract classes can be said to be superclasses that have in them certain elements that should be implemented by inheritance. An abstract class is used because the abstraction that it helps perform simplifies the process of software development.
Assume that we are creating a model based on the walking styles of all animals. Different animals have different ways of walking, and some also have some unique features they exhibit during walking. However, there are some features that are common to all animals while they walk. So we create a class hierarchy, at the base of which is the base class Animal. The things that animals do uniquely while walking can be categorized as abstract methods. The implementation for these methods would be provided by the different subclasses that exist under animal – e.g., cow, snake, goat, man, etc.
Basically, abstract classes can be said to be superclasses that have in them certain elements that should be implemented by inheritance. An abstract class is used because the abstraction that it helps perform simplifies the process of software development.