Abstraction in Java: Definition and How It Works

What Abstraction Means in Java

In plain terms, abstraction means showing only what a user actually needs and hiding everything underneath. In Java, this means the user can access just the information that is relevant to them — that is what we call data abstraction in Java.

Think of driving a car: you only need to know a few essentials — the accelerator, the clutch and the brakes. There is no need to understand how the engine works internally. That is abstraction in its simplest form.

Defining Abstraction in Java

In Java, abstraction means hiding implementation details from the user while exposing only the functionality. The user focuses on what something does, not how it does it. An object holds a lot of information, and abstraction lets us reveal only the relevant part, which reduces programming complexity and effort. It is one of the core concepts of OOPs.

Take a banking application. A customer can check their balance, view a mini statement, or change a password — while the software hides the fetch and update operations behind the scenes. Those operations add no value for the customer, who simply wants to use the application's features.

Java achieves abstraction through abstract classes and interfaces. An abstract class can provide anywhere from 1% to 100% abstraction, while an interface can provide full 100% abstraction. We cover both below.

How to Achieve Abstraction in Java

1. Abstract Class

A class declared with the abstract keyword is an abstract class. It can contain abstract methods (methods without a body) as well as concrete or non-abstract methods (methods with a body). A normal class cannot hold any abstract method. The abstraction level of an abstract class ranges from 1 to 100 percent, depending entirely on its abstract methods: a mix of abstract and non-abstract methods places it between 1 and 100, while a class containing only abstract methods reaches 100% abstraction. You can include as many abstract methods as your design requires.

Abstract class in Java explained with example
Abstract class concept

Explore Abstract Class Abstract Method Guide

2. Interface

An interface is the path to 100% abstraction in Java. It serves as a blueprint for a class and can hold methods and variables like a class, but its methods are abstract by default — meaning only methods without bodies. Since Java 8, however, default methods can also be defined in an interface.

Interface as a blueprint for 100 percent abstraction in Java
Interface blueprint

Learn Interfaces Default Methods

Abstract Class vs Concrete Class

Abstract Class

  • A class declared with the abstract keyword is an abstract class, and it can combine abstract methods (no body) with concrete or non-abstract methods (with body).
  • It must contain at least one abstract method, whereas a normal class cannot contain any abstract method.
  • It is declared using only the abstract keyword — you cannot create one without that special keyword, which signals the JVM to treat it as abstract so it can hold abstract methods.
  • It can have both abstract and concrete (non-abstract) methods. Declaring an abstract method in any class forces that class to be abstract, otherwise a compilation error occurs — this is the general rule.
  • An abstract class may or may not contain abstract methods.
  • It cannot be declared final, because final and abstract are opposites in Java. An abstract class must be inherited by a derived class, which supplies implementations for its abstract methods; a final class, by contrast, cannot be extended. The two concepts therefore conflict.
  • You cannot instantiate an abstract class. Allowing such an object would create two problems: first, the abstract method has no body, so calling it through that object would be meaningless; second, abstract classes are only templates — an object must come from a concrete class, since an object is itself concrete. An abstract class is useless without a concrete class, because it can only be used once a concrete class extends it.
Abstract class versus concrete class comparison in Java
Abstract vs concrete

Concrete Class

  • In Java, a simple class without the abstract keyword is a concrete class. It implements every abstract method of its parent abstract class and provides implementations for all methods of the interfaces it implements.
  • It is declared as an ordinary Java class, without the abstract keyword — meaning it is a complete class. Abstract classes are incomplete because of their abstract methods, but concrete classes are considered complete.
  • It cannot contain any abstract methods. Declaring an abstract method in any class forces that class to be abstract, otherwise a compilation error occurs — the general rule again.
  • It cannot hold any abstract methods.
  • A concrete class can be declared final. Any concrete class may be made final as needed, and a final class cannot be extended by another class.
  • You can create an object of a concrete class. A concrete class works independently of any abstract class, since it is complete and self-sufficient.
Concrete class characteristics in Java
Concrete class traits

Abstract Class vs Interface

Abstract classes and interfaces are both popular Java concepts, and both are used to achieve abstraction. Their differences are numerous.

Declaration and Use

An interface is declared with the interface keyword, and subclasses use the implements keyword to implement it. An abstract class is declared with the abstract keyword, and subclasses use the extends keyword to extend it.

Declaration differences between abstract class and interface
Declaration differences

Variables

Every variable in an interface is static and final by default, so you must initialize them or the compiler throws an exception at compile time. An abstract class may hold final, non-final, static and non-static variables; a final variable must be initialized, otherwise the compiler throws an exception at compile time.

Variable rules in interface versus abstract class
Variable rules

Method Keywords

All methods in an interface are public and abstract by default. You may declare methods with public, private, abstract, default, static and strictfp modifiers. Using the protected modifier throws a compile-time exception because it is not permitted. Since Java 8, default and static methods can be defined in an interface, and since Java 9, private methods too. An abstract class is more flexible than an interface when declaring methods — you can define abstract methods with the protected modifier as well. Interfaces have supported static and default methods since Java 8, while abstract classes could define static and default methods even before Java 8.

Method modifier differences between interface and abstract class
Method modifiers

Inheritance

An interface can extend more than one interface, allowing multiple inheritance of type. An abstract class, by contrast, can extend only one class.

Inheritance rules for interfaces and abstract classes
Inheritance rules
Interface inheritance example in Java
Interface inheritance
Abstract class inheritance example in Java
Abstract class inheritance
Summary of abstraction in Java
Abstraction summary

Keep Exploring Javagoal

Deepen your Java knowledge with related topics across the site.

Connect With Javagoal

Javagoal YouTube channel
Watch on YouTube
Javagoal Instagram profile
Follow on Instagram

Chat Now Facebook Video available in Hindi

Abstraction keeps your Java code focused on what an object does rather than how it does it. By exposing only the methods that matter and hiding the internal steps, you make classes easier to use, change and test. Abstract classes and interfaces are the two tools Java gives you for this, and choosing the right one depends on how much shared behavior and flexibility your design needs.