What Are Abstract Classes?
You'll learn: What abstract classes are and why Java provides them as incomplete blueprints that cannot exist on their own.
The Core Idea
An abstract class is a class that is intentionally incomplete. It's declared using the abstract keyword and serves as a partial blueprint that other classes can extend and complete. You cannot create instances of an abstract class directly—it exists only to be inherited by concrete (complete) subclasses.
Think of an abstract class like an architectural template. A building plan labeled "Generic Building" might define that all buildings have walls and a roof, but it doesn't specify exactly what kind of building it is. You can't construct "Generic Building"—you must first decide whether you're building a house, office, or warehouse. Those concrete types complete the template.
Why Abstract Classes Matter
Abstract classes let you:
- Define common structure and behavior that multiple subclasses share
- Enforce that certain classes must be extended before they can be used
- Declare methods that subclasses must implement (we'll explore this soon)
You create an abstract class by adding the abstract modifier:
public abstract class Animal {
// This class cannot be instantiated
}
If you tried to write new Animal(), the compiler would reject it. You must create a concrete subclass:
public class Dog extends Animal {
// Dog is concrete and can be instantiated
}
Dog myDog = new Dog(); // This works
Key Takeaway: Abstract classes are incomplete blueprints marked with the abstract keyword—they cannot be instantiated directly and must be extended by concrete subclasses that complete their implementation.