Java Abstraction

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.

Abstract Class

A class that contains the abstract keyword in its declaration is known as an abstract class.

  1. Abstract classes may or may not contain abstract methods, i.e., methods without a body ( public void get(); )
  2. But, if a class has at least one abstract method, then the class must be declared abstract.
  3. If a class is declared abstract, it cannot be instantiated.
  4. To use an abstract class, you have to inherit it from another class, provide implementations to the abstract methods in it.
  5. If you inherit an abstract class, you have to provide implementations to all the abstract methods in it.