Test your understanding of Object-Oriented Programming (OOP) in Python with these carefully crafted True or False questions on encapsulation. Great for beginners and intermediate learners to reinforce OOP concepts.
❌ False – Encapsulation can also be achieved using protected variables (`_`) and getter/setter methods, not just strict private variables.
❌ False – A single underscore is a convention for "protected" members, but Python does not enforce access restrictions—it’s still accessible.
✅ True – Encapsulation restricts direct access to data, reducing unintended changes.
✅ True – Python does not enforce strict private members; privacy is convention-based (`_` and `__`).
❌ False – Encapsulation also improves maintainability, reduces bugs, and helps in modular design—not just security.
❌ False – Name mangling (`__var`) makes it harder to access, but it can still be accessed using `_ClassName__var`.
❌ False – Python properties (`@property`) can be used to control access without explicit getter/setter methods.
✅ True – Encapsulation is about controlling access to data, and exposing all attributes breaks this principle.
✅ True – `@property` lets you add logic when getting/setting attributes while keeping the interface clean.
✅ True – Due to name mangling, a subclass cannot directly access `__var` from a parent, but it can via `_ParentClass__var`.