Compare abstract class vs interface — state, constructors… — Cracked Java
// Object-Oriented Programming · Abstract Classes vs Interfaces (Post Java 8)
MidTheoryEPAMAmazonGoogle

Compare abstract class vs interface — state, constructors, multiple inheritance, default methods, when to use.

The remaining real differences are state, constructors, and multiple inheritance — every other contrast people cite (abstract methods, partial implementations, default methods) has been blurred since Java 8. A clean answer enumerates the differences in a table, then closes with a "when to use" rule.

Side-by-side

AspectAbstract classInterface
Instance state (fields)YesNo (only public static final constants)
ConstructorsYesNo
Method bodiesConcrete or abstract methodsabstract, default, static, private (J9+)
Access modifierspublic / protected / package / privatepublic only on abstract/default; private on helpers
Inheritance per classOne abstract class can be extendedMany interfaces can be implemented
Inheritance of stateYes (fields)No
Constructor of subtype callssuper(...) to the abstract classNo constructor to call on an interface
Can be instantiatedNo (must be subclassed)No (must be implemented)
Designed for"is-a" + shared stateCapability contract
EvolutionAdd a method = breaking changeAdd a default method = source-compatible

What still tips the choice

// Abstract class — partial implementation + state
public abstract class HttpServer {
    private final int port;                          // shared state
    protected HttpServer(int port) { this.port = port; }
    public final void start() { bind(port); accept(); }   // template method
    protected abstract void accept();                // hook
}

// Interface — capability the implementer mixes in
public interface MetricsPublisher {
    void publish(String name, double value);
    default void publishCount(String name) { publish(name, 1.0); }
}

public final class NettyServer
        extends HttpServer
        implements MetricsPublisher, AutoCloseable {     // multiple capabilities
    public NettyServer(int port) { super(port); }
    @Override protected void accept()                    { /* ... */ }
    @Override public    void publish(String n, double v) { /* ... */ }
    @Override public    void close()                     { /* ... */ }
}

HttpServer owns port state and enforces a startup sequence — that's an abstract class. MetricsPublisher is a sideways capability — that's an interface. NettyServer combines them.

When to use which

  • Abstract class when you need (a) shared instance fields, (b) a constructor that enforces invariants on every subtype, or (c) a strict "is-a" hierarchy with partial implementation.
  • Interface for everything else — capabilities, contracts, multiple-inheritance-friendly designs, library evolution.

If you can't decide, lean interface. You can always introduce an abstract AbstractFoo skeletal implementation alongside the interface (the JCF pattern — List + AbstractList). That gives implementers a choice: extend the skeletal class for convenience, or implement the interface fresh.

Mark your status