Java Zero to All All questionsPractise free
Interview questions › Java Foundations — Zero to Basics › OOP III — Encapsulation, Abstraction, Enums

Explain the difference between abstraction and encapsulation, since interviewers often conflate them.

Level II · JuniorOOP III — Encapsulation, Abstraction, Enums
Short answer

Abstraction is about the design view — exposing a simple, intention-revealing interface and hiding the complexity of how a job is done (e.g., a Repository interface hiding SQL).

Explanation

Encapsulation is the implementation mechanism — bundling state with the methods that operate on it and restricting direct access to that state. Abstraction is 'what to expose'; encapsulation is 'how to protect what you hid'. You use encapsulation (access modifiers) to enforce the boundaries that abstraction defines.

Common mistakes
  • Using the two terms interchangeably.
  • Saying abstraction is only about abstract classes.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for OOP III — Encapsulation, Abstraction, Enums.

Practise free

More on OOP III — Encapsulation, Abstraction, Enums