---
description: Abstraction is selecting data from a larger pool to show only the relevant details to the object. In Java, abstraction is accomplished using Abstract classes and interfaces. It is one of the most important concepts of OOPs.
title: What is Abstraction in Java? (with Example)
image: https://www.guru99.com/images/abstraction-in-java.png
---

[Skip to content](#main)

**⚡ Smart Summary**

Data Abstraction in Java is an object-oriented concept that shows only essential attributes and hides unnecessary details, reducing complexity through abstract classes and abstract methods, while differing from encapsulation and supporting reusable, maintainable designs across many applications.

- 🎭 **Abstraction Defined:** Shows only essential attributes and hides unnecessary implementation details from the user.
- 🏦 **Real Example:** A banking application selects only relevant customer data, which becomes reusable master data.
- 🆚 **Abstraction vs Encapsulation:** Abstraction solves design-level problems; encapsulation handles implementation by binding code and data.
- 🧱 **Abstract Class:** Contains at least one abstract method, cannot be instantiated, and can mix abstract and concrete methods.
- 📐 **Abstract Method:** Declares only the signature without a body and must be implemented by subclasses.
- 🔒 **Final Keyword:** A final class cannot be inherited, a final method cannot be overridden, and a final variable is constant.

Read More

![Data Abstraction in Java](https://www.guru99.com/images/abstraction-in-java.png)

## What is Abstraction in Java?

**Abstraction** is the concept of object-oriented programming that “shows” only essential attributes and “hides” unnecessary information. The main purpose of abstraction is hiding the unnecessary details from the users. Abstraction is selecting data from a larger pool to show only relevant details of the object to the user. It helps in reducing programming complexity and efforts. It is one of the most important concepts of OOPs.

Click [here](https://www.guru99.com/faq#faq1) if the video is not accessible  

## Let’s Study Abstraction in OOPs with example:

Suppose you want to create a banking application and you are asked to collect all the information about your customer. There are chances that you will come up with following information about the customer

[![Abstraction in Java]()](https://www.guru99.com/images/abstraction_in_oops_112.png)

*Abstraction in Java*

But, not all of the above information is required to create a banking application. So, you need to select only the useful information for your [banking application](https://www.guru99.com/banking-application-testing.html) from that pool. Data like name, address, tax information, etc. make sense for a banking application which is an Abstraction example in OOPs

[![Abstraction in Java]()](https://www.guru99.com/images/abstraction_in_oops_2.png)

Since we have fetched/removed/selected the customer information from a larger pool, the process is referred as Abstraction in [OOPs](https://www.guru99.com/java-oops-concept.html). However, the same information once extracted can be used for a wide range of applications. For instance, you can use the same data for hospital application, job portal application, a Government database, etc. with little or no modification. Hence, it becomes your Master Data. This is an advantage of Abstraction 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](https://www.guru99.com/encapsulation-in-java.html) 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. |

**Don't Miss:**

- [Arrays in Java](https://www.guru99.com/java-arrays.html)
- [Java Swing Tutorial: How to Create a GUI Application in Java](https://www.guru99.com/java-swing-gui.html)
- [Java Tutorial for Beginners: Complete Guide](https://www.guru99.com/java-tutorial.html)
- [Insertion Sort Algorithm in Java with Program Example](https://www.guru99.com/insertion-sort-java.html)

## What is Abstract Class?

**ABSTRACT CLASS** is a type of class in Java, that declare one or more abstract methods. These classes can have abstract methods as well as concrete methods. A normal class cannot have abstract methods. An abstract class is a class that contains at least one abstract method. We can understand the concept by the **shape example in java**.

Consider the following class hierarchy consisting of a Shape class which is inherited by three classes Rectangle, Circle, and Triangle. The Shape class is created to save on common attributes and methods shared by the three classes Rectangle, Circle, and Triangle. calculateArea() is one such method shared by all three child classes and present in Shape class.

[![Abstract Class in Java]()](https://www.guru99.com/images/uploads/2012/06/java-abstract-classes.jpg)

*Shape Abstraction Example*

Now, assume you write code to create objects for the classes depicted above. Let’s observe how these **objects will look in a practical world.** An object of the class rectangle will give a rectangle, a shape we so commonly observed in everyday life.

[![Abstract Class]()](https://www.guru99.com/images/uploads/2012/06/Java_Abstract.png)

An object of the class triangle will give a triangle, again a common everyday shape.

[![Abstract Class]()](https://www.guru99.com/images/uploads/2012/06/Java_Abstract_1.png)

But what would an object of Class Shape look like in a practical world ??

[![Abstract Class]()](https://www.guru99.com/images/uploads/2012/06/java_abstract_method.png)

If you observe the Shape class serves in **our goal of achieving [inheritance](https://www.guru99.com/inheritance-in-java.html) and polymorphism.** But it was not built to be instantiated. Such classes can be labelled **Abstract**. An abstract java class cannot be instantiated.

**Syntax:**

```
abstract class Shape{
	// code
}
```

It is possible that you DO NOT label Shape class as Abstract and then instantiate it. But such object will have no use in your code and will open a room for potential errors. Hence this is not desirable.

## What are Abstract Methods in Java?

**ABSTRACT METHOD** in Java, is a method that has just the method definition but does not contain implementation. A method without a body is known as an Abstract Method. It must be declared in an abstract class. The abstract method will never be final because the abstract class must implement all the abstract methods.

As we all know, the formula for calculating area for rectangle, circle, & triangle is different. The calculateArea() method will have to be overridden by the inheriting classes. It makes no sense defining it in the Shape class, **but we need to make sure that all the inheriting classes do have the method.**

Such methods can be labeled **abstract.**

**Syntax:**

```
abstract public void calculateArea();
```

For an **abstract method, no implementation is required.** Only the signature of the method is defined.

## Abstraction Code Example

```
abstract class Shape{
  abstract void calculateArea();
}
 class guru99 extends Shape{
void calculateArea(){System.out.println("Area of Shape");}
public static void main(String args[]){
 Shape obj = new guru99();
 obj.calculateArea();
}
}
```

## Advantages of Abstraction

- The main benefit of using an Abstraction in [Programming](https://www.guru99.com/computer-programming-tutorial.html) is that it allows you to group several related classes as siblings.
- Abstraction in Object Oriented Programming helps to reduce the complexity of the design and implementation process of software.

## Final Keyword in Java

The final modifier applies to classes, methods, and variables. The meaning of final varies from context to context, but the essential idea is the same.

- A final class cannot be inherited
- A final variable becomes a constant and its value cannot be changed.
- A final method cannot be overridden. This is done for security reasons, and these methods are used for optimization.

**Example** :- To learn abstract & final keywords

**Step 1)** Copy the following code into an Editor.

```
abstract class Shape{
   final int b = 20;
   public void display(){
     System.out.println("This is display method");
   }
   abstract public void calculateArea();
}

public class Rectangle extends Shape{
   public static void main(String args[]){
      Rectangle obj = new Rectangle();
      obj.display();
     //obj.b=200;
  }
  //public void calculateArea(){}
}
```

**Step 2)** Save , Compile & Run the code.

**Step 3)** Error =? The abstract method is not implemented int the class Rectangle. To fix the issue uncomment line #15.

**Step 4)** Uncomment line # 13. Save & Compile the code.

**Step 5)** Error = ? variable b is final

## When to use Abstract Methods & Abstract Class?

Abstract methods are mostly declared where two or more subclasses are also doing the same thing in different ways through different implementations. It also extends the same Abstract class and offers different implementations of the abstract methods.

Abstract classes help to describe generic types of behaviors and object-oriented programming class hierarchy. It also describes subclasses to offer implementation details of the abstract class.

## FAQs

🧩 What are the two types of abstraction in Java?

Java provides two types of abstraction: data abstraction, achieved with abstract classes (partial abstraction), and full abstraction, achieved with interfaces. Both hide implementation details and expose only essential features.

🏗️ Can an abstract class have a constructor in Java?

Yes. An abstract class can have a constructor, which is called when a subclass object is created. It is used to initialize common fields shared by the inheriting subclasses.

🚫 Why can an abstract class not be instantiated?

An abstract class cannot be instantiated because it may contain abstract methods without implementation. It exists to be inherited, letting subclasses provide concrete implementations of those methods.

🤖 How does AI use abstraction concepts in software design?

AI tools apply abstraction by generating abstract classes and interfaces, recommending which details to hide, and refactoring code to reduce complexity. This helps developers design cleaner, more maintainable object models.

🧠 Can AI generate abstract classes and methods in Java?

Yes. AI coding assistants can create abstract classes, define abstract methods, and scaffold subclasses with required implementations, helping beginners apply abstraction correctly in object-oriented Java programs.

#### Summarize this post with:

ChatGPTPerplexityGrokGoogle AI

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.**

##### Sign up for the newsletter

Subscribe for Free

You have successfully subscribed.  
Please check your inbox.

![AI-Newsletter]() Chosen by over **350,000+** professionals

[Scroll to topScroll to top](#wrapper) Scroll to top

×

Toggle Menu Close

Search for:

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/abstraction-in-java.png","url":"https://www.guru99.com/images/abstraction-in-java.png","width":"700","height":"250","caption":"Abstraction in Java","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/java-data-abstraction.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/java-tutorials","name":"Java Tutorials"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/java-data-abstraction.html","name":"What is Abstraction in Java? (with Example)"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/java-data-abstraction.html#webpage","url":"https://www.guru99.com/java-data-abstraction.html","name":"What is Abstraction in Java? (with Example)","dateModified":"2026-06-30T16:43:51+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/abstraction-in-java.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/java-data-abstraction.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/james","name":"James Hartman","description":"I am James Hartman, a seasoned professional in Oracle Certified Java Professional tutorials, specializing in crafting comprehensive guides to help you excel in your Java certification journey.","url":"https://www.guru99.com/author/james","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/james-hartman-author-v2-120x120.png","url":"https://www.guru99.com/images/james-hartman-author-v2-120x120.png","caption":"James Hartman","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"Java Tutorials","headline":"What is Abstraction in Java? (with Example)","description":"Abstraction is selecting data from a larger pool to show only the relevant details to the object. In Java, abstraction is accomplished using Abstract classes and interfaces. It is one of the most important concepts of OOPs.","keywords":"java","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/james","name":"James Hartman"},"dateModified":"2026-06-30T16:43:51+05:30","image":{"@id":"https://www.guru99.com/images/abstraction-in-java.png"},"copyrightYear":"2026","name":"What is Abstraction in Java? (with Example)","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What are the two types of abstraction in Java?","acceptedAnswer":{"@type":"Answer","text":"Java provides two types of abstraction: data abstraction, achieved with abstract classes (partial abstraction), and full abstraction, achieved with interfaces. Both hide implementation details and expose only essential features."}},{"@type":"Question","name":"Can an abstract class have a constructor in Java?","acceptedAnswer":{"@type":"Answer","text":"Yes. An abstract class can have a constructor, which is called when a subclass object is created. It is used to initialize common fields shared by the inheriting subclasses."}},{"@type":"Question","name":"Why can an abstract class not be instantiated?","acceptedAnswer":{"@type":"Answer","text":"An abstract class cannot be instantiated because it may contain abstract methods without implementation. It exists to be inherited, letting subclasses provide concrete implementations of those methods."}},{"@type":"Question","name":"How does AI use abstraction concepts in software design?","acceptedAnswer":{"@type":"Answer","text":"AI tools apply abstraction by generating abstract classes and interfaces, recommending which details to hide, and refactoring code to reduce complexity. This helps developers design cleaner, more maintainable object models."}},{"@type":"Question","name":"Can AI generate abstract classes and methods in Java?","acceptedAnswer":{"@type":"Answer","text":"Yes. AI coding assistants can create abstract classes, define abstract methods, and scaffold subclasses with required implementations, helping beginners apply abstraction correctly in object-oriented Java programs."}}]}],"@id":"https://www.guru99.com/java-data-abstraction.html#schema-26110","isPartOf":{"@id":"https://www.guru99.com/java-data-abstraction.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/java-data-abstraction.html#webpage"}}]}
```
