Skip to content
  • Encapsulation · OOPs

Encapsulation

LearnViaNotes @learnvianotes· 1 min read

Wrapping data and member functions together in a single unit (class). Like a capsule that hides the medicine inside.

// Bad — no encapsulation

Student s; s.age = -5;  // invalid, but allowed


// Good — encapsulated

s.setAge(-5);  // setter rejects invalid value

s.setAge(20);  // valid, stored safely

Free for students and teachers

Write notes like this one

Cards for every idea, quizzes and flashcards, read aloud — on the web and your phone.

Something wrong with this note? Open it to report