Abstract classes and interfaces both define abstraction, but they are used for different design intentions.

Abstract Class

An abstract class cannot be instantiated directly. It provides a common base for related classes.

It can contain:

abstract class ImportJob {
    void recordStart() { System.out.println("Import started"); }
    abstract void importData();
}

Use an abstract class when related classes share common state or behavior.

Interface

An interface defines a contract: what a class can do.

interface Payment {
    void pay();
}

class UpiPayment implements Payment {
    public void pay() {
        System.out.println("Paid using UPI");
    }
}

Use an interface when unrelated classes share a capability.

Key Difference

Example:

Comparison

Abstract Class Interface
Uses extends Uses implements
Is-a relationship Can-do capability
Can have shared state Usually behavior contract
Can have constructors Cannot have constructors
One class can extend one class One class can implement many interfaces

Interview Notes