Hiding internal details and showing functionality is known as abstraction. For example phone call, we don’t know the internal processing.
The user will have the information on what the object does instead of how it does it.
In Java, abstraction is achieved using Abstract classes and interfaces.
In Java, we use abstract class and interface to achieve abstraction.
A class that contains the abstract keyword in its declaration is known as an abstract class.
- Abstract classes may or may not contain abstract methods, i.e., methods without a body ( public void get(); )
- But, if a class has at least one abstract method, then the class must be declared abstract.
- If a class is declared abstract, it cannot be instantiated.
- To use an abstract class, you have to inherit it from another class, provide implementations to the abstract methods in it.
- If you inherit an abstract class, you have to provide implementations to all the abstract methods in it.