Lesson 4 of 516 minModule progress 0%

Module 6: Inheritance and Polymorphism

Abstract Classes

Create parent classes that define shared structure and required behavior without allowing direct object creation.

Author

Java Learner Editorial Team

Reviewer

Technical review by Java Learner

Last reviewed

2026-04-16

Java version

Java 25 LTS

How this lesson was prepared: AI-assisted draft, edited by hand, and checked against current Java 25 documentation and runnable examples.

Learning goals

  • Understand what makes a class abstract
  • Know why abstract classes cannot be instantiated directly
  • Use abstract methods to require child implementations

An abstract class is a base class that is not complete on its own: It provides shared structure for subclasses but is not meant to create direct objects.

Abstract methods have no body: They tell child classes, “you must provide this behavior.”

**This is useful when several related classes share some code but must each define part of the behavior themselves.

Good beginner mental model: An abstract class is a template for related child classes.

Runnable examples

An abstract class requires child classes to finish the behavior

abstract class Shape {
    abstract double area();
}

class Square extends Shape {
    double side;

    Square(double side) {
        this.side = side;
    }

    @Override
    double area() {
        return side * side;
    }
}

Expected output

Square must implement the abstract `area()` method before it becomes a usable class.

Mini exercise

Create an abstract `Employee` class with an abstract `monthlyPay()` method, then implement it in one child class.

Summary

  • Abstract classes are templates for related child classes.
  • They can contain abstract methods that children must implement.
  • You cannot create objects directly from an abstract class.

Next step

Finish the module with interfaces, which define capabilities that many different classes can agree to support.

Sources used

Advertisement

Lesson check

Why can’t you create an object directly from an abstract class?

Next lesson →