InternDoor

OOP · 1 min · daily challenge of 2026-10-29

How encapsulation differs from abstraction

Learn how abstraction hides how an object works, while encapsulation bundles data with methods to enforce rules and protect internal state.

Practise OOPMore videos

The quiz

Keeping fields private and exposing behaviour through methods is an example of:

  1. Inheritance
  2. Abstraction of hardware
  3. Polymorphism
  4. Encapsulation
Show the answer

D. Encapsulation

Transcript

This daily challenge question caught people out: why do classes keep fields private?

Encapsulation bundles data with methods. Inside BankAccount, your balance is private, so a negative deposit gets refused before touching the internal state.

Without encapsulation, outside code can change data directly and bypass validation. But with private fields, every deposit must strictly follow your class rules.

Here is the key idea: abstraction shows what an object does and hides how, while encapsulation binds data with methods to block changes directly.

So, a List interface hides whether nodes or arrays run underneath, while a BankAccount hides its balance to refuse any illegal updates safely.

Now, keeping fields private and exposing behaviour only through methods is an example of what? Pause the video right now and pick your option.

The correct option is D, encapsulation. Option A is wrong because inheritance focuses on sharing code through a class hierarchy, not data protection.

Encapsulation protects data, while abstraction hides implementation. Save this to revise before your semester exams, and practice core concepts daily on InternDoor.

More study videos

All videos
Learned it? See who is hiring

Engineering internships and entry-level jobs in India, newest first.