What is encapsulation in object-oriented programming?

Technical
Easy
Infosys
138.5K views

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 integrity and hides complex implementation details from the outside world.

Common Mistakes to Avoid

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

Practice This Question with AI

Answer this question orally or via text and get instant AI-powered feedback on your response quality, structure, and delivery.

Start Practicing

Related Interview Questions

Browse all 78 Technical questionsBrowse all 65 Infosys questions