juniorOOP

What is encapsulation in OOP?

Updated May 17, 2026

Short answer

Encapsulation is bundling data and methods together and restricting direct access.

Deep explanation

Encapsulation hides internal state and exposes controlled access via methods. It improves security, maintainability, and modularity.

Real-world example

Bank systems hide account balance and expose only deposit/withdraw methods.

Common mistakes

  • Directly exposing class fields as public variables.

Follow-up questions

  • Why is data hiding important?
  • How does encapsulation improve maintainability?

More OOP interview questions

View all →