What is encapsulation in object-oriented programming?

Technical
Easy
Infosys
138.5K views

Direct Answer

A specific question targeting one of the four pillars of OOP.

Why Interviewers Ask This

Encapsulation is a fundamental concept that protects data integrity. Interviewers check if the candidate understands how to hide internal states and expose only necessary interfaces. It tests attention to detail in design.

How to Answer This Question

Define encapsulation as bundling data and methods together. Explain how access modifiers control visibility. Discuss the benefits of hiding implementation details. Provide a simple example like a class with private variables.

Key Points to Cover

  • Bundle data and methods
  • Use access modifiers
  • Ensure data integrity
  • Hide implementation

Sample Answer

Encapsulation is the bundling of data and methods that operate on that data within a single unit, like a class. It restricts direct access to some components using access modifiers like private. This ensures data integri…

Common Mistakes to Avoid

  • Confusing with inheritance
  • Ignoring access modifiers
  • Failing to explain benefits
  • Lacking examples

Sound confident on this question in 5 minutes

Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.

Try it free

Related Interview Questions

Browse all 180 Technical questionsBrowse all 149 Infosys questions