Question
Which OOP principle allows for restricting access to
certain parts of an object while exposing only necessary parts for interaction?Solution
Encapsulation is a fundamental principle of OOP that involves bundling data (attributes) and methods (functions) that operate on the data into a single unit or class. It also restricts direct access to some components of the object, typically by declaring them private or protected. Access is then controlled through public methods known as getters and setters. Encapsulation ensures security and prevents unauthorized or accidental modification of data. For instance, in a class BankAccount , the balance attribute might be private, and only specific methods like deposit() or withdraw() are accessible to modify it. This safeguards the integrity of the data and prevents incorrect usage. Why Other Options Are Wrong Option A : "Polymorphism" Polymorphism deals with methods behaving differently for different object types, not with restricting access. Option C : "Inheritance" Inheritance allows a child class to use the properties and methods of a parent class but does not involve controlling access to data. Option D : "Abstraction" Abstraction hides complexity by exposing only essential features. However, encapsulation is specifically about access control at the data and method level. Option E : "Message Passing" Message passing refers to the communication between objects in OOP but does not control access to internal object components.
Volta River flows in which country?
Who finished second in the SuperUnited Rapid and Blitz 2025 chess tournament?
How many Fair Price Shops are covered under the 'Anna Chakra' platform?
As per Union Budget 2023-24, how many legal provisions have been decriminalized for enhancing ease of doing business?
One Nation Corporate Card has been launched with the ability to function as a National Transit Card, enabling cardholders to travel throughout India on ...
Statements:
1. Amendments to the MSME Act were proposed during International MSME Day 2024.
2. The TEAM Initiative facilitates onboarding ...
Australia will ban children under what age from creating YouTube accounts starting December?
Which statement is correct about “The International Day of Yoga”? Â
a.   The theme for International Yoga Day is "Yoga for Vasudhaiva...
What does the newly launched RailOne app by Indian Railways offer a 3% discount on?Â
Dayside Investment, an affiliate of Warburg Pincus, has sold how much of its stake in IDFC First Bank?Â