Abstraction & Abstract Classes in Java
Abstraction means exposing only what a piece of code needs to know to use something, hiding the messier details of how it actually works underneath — calling ArrayList's add() method requires knowing nothing about resizing arrays internally. An abstract class is one specific Java tool for this: declared with the abstract keyword, it can define abstract methods that have a signature but no body at all, forcing every concrete, non-abstract subclass to supply its own implementation.
An abstract class can never be instantiated directly with new, even though it can still hold regular fields, constructors, and fully-implemented ordinary methods alongside its abstract ones. It exists specifically to be extended, providing shared structure and implementation while leaving certain pieces deliberately unfinished for each subclass to complete in its own way.
Abstraction hides implementation detail
Using something only requires knowing its interface, not the mechanics behind it.
Declaring an abstract class
The abstract keyword on a class means it can never be instantiated directly with new.
Abstract methods have no body
Just a signature ending in a semicolon, with the actual implementation left to subclasses.
Concrete subclasses must implement every abstract method
Or themselves also be declared abstract, deferring that obligation further down the hierarchy.
Abstract classes can still hold real code
Regular fields, constructors, and fully-implemented ordinary methods can sit right alongside the abstract ones.
abstract class Shape { abstract double area(); void describe() { System.out.println("Area: " + area()); }} class Square extends Shape { double side; Square(double side) { this.side = side; } double area() { return side * side; }} public class AbstractDemo { public static void main(String[] args) { Shape s = new Square(4); s.describe(); }}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Java yourself — building beats watching.