Abstraction Oop

What is Abstraction in OOPs? Java Abstract Class & Method

The idea behind object-oriented programming known as abstraction is to “hide” information that is not necessary while “showing” only the properties that are absolutely necessary. The primary objective of abstraction is to shield users from information that is not relevant to their needs. The process of picking data from a bigger pool so that only pertinent aspects of an object are displayed to the user is known as abstraction. It helps reduce the complexity of the code and the amount of effort required. It is without a doubt one of the most essential ideas in OOPs.

Let’s Study Abstraction in OOPs with example:

Imagine you have been tasked with developing a banking application and have been told to gather all of the information you can on your customers. There is a possibility that you will learn the following facts about the client:

Java’s approach to abstraction
Java’s approach to abstraction
To make a banking application, however, you do not need all of the aforementioned pieces of information.

Therefore, out of that pool of data, you need to extract only the information that is relevant to your banking application. For a banking application, which is an example of abstraction in OOPs, it makes sense to store data such as a user’s name, address, and tax information, etc.
Java’s approach to abstraction
The technique is known as Abstraction in OOPs because the client information was retrieved, extracted, and picked from a broader pool of data.

On the other hand, once the information has been extracted, it can be used for a broad variety of different purposes. For example, you need very little or no modification to use the same data for an application to a hospital, an application to a job portal, a database maintained by the government, and so on. As a result, it turns into your Master Data. This is one of the benefits that abstraction offers in OOPs.

Difference between Abstraction and Encapsulation

Abstraction Encapsulation
Abstraction in Object Oriented Programming solves the issues at the design level. Encapsulation solves it implementation level.
Abstraction in Programming is about hiding unwanted details while showing most essential information. Encapsulation means binding the code and data into a single unit.
Data Abstraction in Java allows focussing on what the information object must contain Encapsulation means hiding the internal details or mechanics of how an object does something for security reasons.

Difference between Abstract Class and Interface

Abstract Class Interface
An abstract class can have both abstract and non-abstract methods. The interface can have only abstract methods.
It does not support multiple inheritances. It supports multiple inheritances.
It can provide the implementation of the interface. It can not provide the implementation of the abstract class.
An abstract class can have protected and abstract public methods. An interface can have only have public abstract methods.
An abstract class can have final, static, or static final variable with any access specifier. The interface can only have a public static final variable.

What is Abstract Class?

In object-oriented programming (OOP), an Abstract Class is a type of class that declares one or more abstract methods. These classes are able to have both concrete and abstract methods in their repertoire. Abstract methods cannot be implemented in conventional classes. At least one abstract method must be present for a class to be considered an abstract class.

What are Abstract Methods?

A method is considered to be abstract if it only contains the method specification and does not include any implementation. Abstract methods are methods that do not have a body associated with them. A declaration for it must be made in an abstract class. Because the abstract class is required to implement all of the abstract methods, the abstract method will never reach its final state.

Advantages of Abstraction

When it comes to programming, the primary advantage of utilising an Abstraction is that it gives you the ability to organise multiple related classes as siblings.
The process of designing and implementing software can be made less complicated by the use of abstraction, which is a component of object-oriented programming.
When should Abstract Methods and Abstract Classes be Used?
The majority of the time, abstract methods are declared in situations when two or more subclasses are also doing the same functionality, although in a variety of unique ways due to distinct implementations. In addition to this, it is an extension of the Abstract class and provides many implementations of the abstract methods.

Abstract classes are useful in object-oriented programming because they assist in describing generic sorts of behaviours and class hierarchies. In addition to this, it describes subclasses, which are used to provide implementation details of the abstract class.