An abstract class is a class that is declared by using the abstract keyword. It may or may not have abstract methods. Abstract classes cannot be instantiated, but they can be extended into sub-classes.
Java provides a special type of class called an abstract class. Which helps us to organize our classes based on common methods. An abstract class lets you put the common method names in one abstract class without having to write the actual implementation code.
An abstract class can be extended into sub-classes, these sub-classes usually provide implementations for all of the abstract methods.
The key idea with an abstract class is useful when there is common functionality associated with subclasses and some behavior is unique to specific classes. So you implement the superclass as an abstract class and define methods that are common to subclasses. Then you implement each subclass by extending the abstract class and adding the methods unique to the class.
Points of an abstract class:
- Abstract class contains abstract methods.
- Program can’t instantiate an abstract class.
- Abstract classes contain a mixture of non-abstract and abstract methods.
- If any class extends the abstract class then it must implement all the abstract methods of the abstract class.
The final class can never act as a Base class whereas the abstract class will always act as a Base class in Inheritance.