An abstract class is also called an incomplete class, in such a class we only prepare the architecture of our logic and implement it in some other class. If a single method is defined as an abstract in a class, then the class will be abstract. Abstract classes and methods are defined using the abstract keyword.
What is Data Abstraction in Java?
Hiding the implementation details from the end user and showing only the functionality is called Abstraction. This means hiding the internal details of any functionality and showing only the working parts is called Abstraction. The main purpose of Abstraction is to enhance security.
Data abstraction is the process of hiding certain details and showing only essential information to the user. Abstraction can be achieved with either abstract classes or interfaces.
Suppose nowadays you chat to communicate with each other, you just enter a message by writing and that message gets shown to the other user. Here you do not know what process has been followed internally to send the message, nor do you know how the implementation will be.
For example: When a Pokeball hits the Pokemon, as long as it is not deflected, the Pokeball will open, causing the Pokemon to shrink, store it inside, and close. A Pokemon in this state is given a chance to struggle to attempt to break free from the ball and escape, instantly growing back in size.
What are the ways to achieve Data Abstraction in Java?
There are two ways to achieve Abstraction in Java:
- Abstract class
Advantages of Data Abstraction in Java
- It reduces the complexity of viewing things.
- Avoids code duplication and increases reusability.
- Helps to increase the security of an application or program as only essential details are provided to the user.
- It improves the maintainability of the application.
- It improves the modularity of the application.
- The enhancement will become very easy because without affecting end-users we can able to perform any type of changes in our internal system.
Abstraction is used to hide background details or any unnecessary implementation of data so that users can see only necessary information. This is one of the most important and essential features of OOPs. Pre-defined functions are similar to data abstraction.