Skip to main content

Section 9.1 Introduction to Abstract Classes

An abstract class is a special type of class in Java that cannot be instantiated directly. This means you cannot create objects from it using the new keyword. Instead, abstract classes are designed to be subclassed (extended) by other classes that provide implementations for their abstract methods.
Abstract classes serve as incomplete templates or blueprints that define:
  • Common state (fields) that subclasses will inherit
  • Some fully implemented methods that all subclasses can use as-is
  • Abstract methods (methods without bodies) that subclasses must implement
The inability to instantiate abstract classes is actually by design. If a class contains one or more abstract methods that have no implementation, it wouldn’t make sense to create objects from it, since those objects wouldn’t know how to respond to calls to the abstract methods.

Subsection 9.1.1 Why Abstract Classes?

You might wonder why you’d ever want to create a class that you can’t actually instantiate. Yet, abstract classes are very useful because they help clearly define what subclasses must implement, without forcing unnecessary duplication. Think of an abstract class as a blueprint or a template for your subclasses.
Document System Example
In a document management system, different document types (PDF, Word, Image) all need methods like save() and print(). An abstract Document class would define these methods as abstract, ensuring all document types implement them.
In a payroll system, you might have an abstract Employee class with an abstract calculatePay() method. Different types of employees (hourly, salaried, commission-based) would each implement this differently.

Insight 9.1.3.

How Classes Evolve to Become Abstract
In real-world software development, abstract classes often emerge through a natural evolution of your codebase rather than being designed from the start. You might initially create concrete (non-abstract) superclasses, but as your system grows, you discover that:
  • Some superclass methods don’t make sense to implement at the superclass level
  • Multiple subclasses keep overriding the same methods with specialized behavior
  • You find yourself creating superclass "instances" that really should be one of the subclasses
These signs often indicate that your design would benefit from converting the superclass into an abstract class. This evolution represents a growing understanding of your problem domain and a natural refinement of your object model.
You have attempted of activities on this page.