Abstraction in Java

Abstraction in Java

In this tutorial, we are going to discuss abstraction in Java. Abstraction is the process of showing only the required information to the user by hiding other details.

For example, consider a mobile phone. We know that pressing the call button will dial the required number. But we don’t know the actual implementation of how a call works. This is because the internal mechanism is not visible to us. This is a real example of abstraction. Similarly, abstraction works in the same way in Object-oriented programming.

Use of Abstraction
  • Hiding implementation details is nothing but abstraction. The main advantages of abstraction are we can achieve security as we are not highlighting internal implementation.
  • Enhancement will become easy. With out effecting outside person we can change our internal implementation.
Ways to achieve Java Abstraction

We can achieve abstraction in java in 2 ways.

Abstraction in Java

You can refer to the Interface tutorial to understand more about achieving abstraction using an interface.

Note

  • If we don’t know about implementation, we have to represent the specification, and then we should go for an interface.
  • If we don’t know about complete implementation, we have a partial implementation, and then we should go for abstract.
  • If we know complete implementation and are ready to provide service, we should go for a concrete class.
Abstraction in Java

Scroll to top