Skip to main content
PreparationZone Logo
PrepZone

Interfaces and Abstract Classes

How to choose between them, how default methods changed the answer, and what annotations add.

Pass checkpoint below

Why this matters

  • This is the most frequently asked design question in Java interviews, and default methods in Java 8 changed the correct answer.
  • Choosing wrongly shows up later as a class that cannot extend the thing it needs to, because its one extends slot is already taken.
  • Every modern Java API — streams, collections, Spring, JDBC — is defined in interfaces, so reading those APIs requires fluency here.

Interfaces

An interface is a contract. Before Java 8 it could hold nothing but abstract method signatures and constants; three releases have since widened it.

Java
Loading compiler…

Member rules, stated once

  • Methods without a body are implicitly public abstract.
  • Fields are implicitly public static final — constants, never instance state.
  • default methods carry a body that implementers inherit and may override.
  • static methods belong to the interface itself and are not inherited by implementers.
  • private methods exist only to share code between default methods in the same interface.
  • An interface has no constructor and can never be instantiated.

Abstract classes

An abstract class cannot be instantiated and may mix finished and unfinished methods. Crucially, it can hold state and a constructor.

Java
Loading compiler…

Note what describe() does: it calls the abstract area(). The parent defines the algorithm and the child supplies one step. That is the template method pattern, and it is the clearest reason to prefer an abstract class.

Abstract class
Shared fieldsCan hold state
ConstructorsRuns setup for subclasses
One parent onlySingle inheritance
Interface
Constants onlyNo instance state
default / static methodsShared helpers since Java 8
Many at onceMultiple inheritance of type
Reach for an abstract class when subclasses share state and partial behaviour. Reach for an interface when unrelated types need to agree on a capability.

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 5 sections

  • Choosing between them
  • When two interfaces collide
  • Functional interfaces
  • Marker interfaces and annotations
  • Common misreadings

Test yourself

Answer these before moving on — recall is what makes it stick.