Abstraction in Java
An Abstraction is a process of exposing all the necessary details and hiding the rest. In Java, Data Abstraction is defined as the process of reducing the object to its essence so that only the necessary characteristics are exposed to the users.
Abstraction defines an object in terms of its properties (attributes), behavior (methods), and interfaces (means of communicating with other objects).
Real-life Example for Java Abstraction
If we want to process something from the real world, we have to extract the essential characteristics of that object. Consider the example, shown in the figure below.
Here, you can see that an Owner is interested in details like Car description, service history, etc; Garage Personnel are interested in details like License, work description, bill, owner, etc; and Registration Office interested in details like vehicle identification number, current owner, license plate, etc.
It means each application identifies the details that are important to it.
Abstraction can be seen as the technique of filtering out the unnecessary details of an object so that there remain only the useful characteristics that define it. Abstraction focuses on the perceived behavior of the entity. It provides an external view of the entity.
Abstract Classes in JavaAn Abstract class is a class whose objects can’t be created. An Abstract class is created through the use of the abstract keyword. It is used to represent a concept.An abstract class can have abstract methods (methods without body) as well as non-abstract methods or concrete methods (methods with the body). A non-abstract class cannot have abstract methods.The class has to be declared as abstract if it contains at least one abstract method.An abstract class does not allow you to create objects of its type. In this case, we can only use the objects of its subclass.Using an abstract class, we can achieve 0 to 100% abstraction.There is always a default constructor in an abstract class, it can also have a parameterized constructor.The abstract class can also contain final and static methods.