← Back to Java

Abstract Class vs Interface

JavaMidjava

The Question

What is the difference between an abstract class and an interface in Java?

What a Strong Answer Covers

  • abstract class = abstract + concrete methods
  • interface = abstract methods only (+ default/static in Java 8)
  • multiple inheritance via interfaces
  • abstract class uses extends
  • interface uses implements

Senior-Level Answer

Abstract classes and interfaces both enable abstraction, but they serve different design purposes.

An abstract class can contain instance fields, constructors, and a mix of abstract and concrete methods. A subclass extends it using extends and inherits its state and behavior. Java enforces single inheritance for classes — a class can extend only one abstract class. This makes abstract classes appropriate for modeling "is-a" relationships where subclasses share common state.

An interface defines a contract. Prior to Java 8, interfaces could only declare abstract methods and constants. Since Java 8, interfaces can include default methods and static methods. Java 9 added private methods. However, interfaces still cannot have instance fields or constructors — they cannot hold state. A class can implement multiple interfaces, enabling a form of multiple inheritance without the diamond problem.

Default methods narrowed the gap but did not eliminate it. They were designed to allow interface evolution — adding forEach() and stream() to Collection without breaking every implementation. But interfaces still cannot hold mutable state.

Use an abstract class when you need to share state among closely related classes, provide a partial implementation, enforce initialization via constructors, or use non-public members. Use an interface when you want to define a capability that can be mixed into unrelated classes — Comparable, Serializable, Iterable.

A practical pattern is to combine both: define interfaces for public API contracts and abstract classes as skeletal implementations. Java's List (interface) + AbstractList (abstract class) exemplifies this.

Key Differences

AspectAbstract ClassInterface
Instance fieldsYes — can hold stateNo — only constants (public static final)
ConstructorsYesNo
Method typesAbstract + concreteAbstract + default (Java 8+) + static + private (Java 9+)
InheritanceSingle (extends one class)Multiple (implements many interfaces)
Access modifiersAny (public, protected, private, package)Methods public by default; private since Java 9
Design intent"is-a" — shared identity and state"can-do" — shared capability across unrelated types
EvolutionAdding methods may break subclassesDefault methods allow non-breaking additions

What Separates a 2/3 from a 3/3

2/3 — Passing but Incomplete

Explains the core differences: state, constructors, single vs multiple inheritance. Mentions Java 8 default methods.

3/3 — Strong Answer

Covers state, constructors, inheritance model, access modifiers. Explains Java 8 default methods and their purpose. Provides clear decision criteria. References real-world examples like Collections Framework.

Common Mistakes

  • Saying interfaces cannot have any method implementations — incorrect since Java 8
  • Failing to mention that interfaces cannot hold instance state
  • Not explaining WHEN to choose each — listing differences without design guidance
  • Ignoring the skeletal implementation pattern (e.g., AbstractList)
  • Treating Java 8 default methods as making interfaces equivalent to abstract classes

Follow-Up Questions

  • What happens when a class implements two interfaces with the same default method? — Compilation error — must override and explicitly choose using InterfaceName.super.method().
  • Give an example of the skeletal implementation pattern. — List (interface) + AbstractList (abstract class). Clients code to List; implementations extend AbstractList.
  • Why were default methods added in Java 8? — Interface evolution — adding forEach() and stream() to Collection without breaking every implementation.
  • Can an abstract class implement an interface without providing all implementations? — Yes — abstract classes can defer interface method implementation to concrete subclasses.

Related Questions

  • JVM vs JRE vs JDK
  • Java Platform Independence
  • How JVM Works
  • Main Features of Java
  • public static void main

Can You Explain This Cold?

Reading the answer is step one. Explaining it unprompted — under interview pressure — is what actually matters. Get AI-graded feedback on your answer with follow-up probes on your weak points.

Get Graded — Free Assessment
GrindQuestionsAITechnical interview assessment
TermsPrivacyAbout