Abstract class is a class that can’t be instantiated and may contain abstract methods (without implementation). It’s used as a base for other classes to inherit and implement common behavior.

Example

abstract class Animal {
    abstract void makeSound();
    void eat() {
        System.out.println("Eating...");
    }
}
 
class Dog extends Animal {
    void makeSound() {
        System.out.println("Bark");
    }
}
 
Animal animal = new Dog();
dog.makeSound(); // "Bark"
dog.eat();       // "Eating..."

Features

  • Can have abstract and concrete methods.
  • Can have constructors, fields and static methods.
  • Can’t be instantiated directly.
  • Child class must implement all abstract methods.

Comparison

Abstract Class vs Interface

FeatureAbstract ClassInterface
Method TypesAbstract + ConcreteAbstract (default), default, static
Instantiationβœ—βœ—
Constructorsβœ…βœ—
Multiple Inheritanceβœ—βœ…
Access ModifiersAnypublic only (before Java 8)
FieldsAnypublic static final only

Tip

Use abstract clas when you want to share code among related classes.
Use an interface when you want to define a contract without shared implementation.


Parent: _OOP Advanced Tools