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.
The witness gave a ______ account of the events, leaving no room for doubt about what had happened.
A poor man and his family ate ________ little other residents of the town were kind enough to spare. One day, when he and his family sat down to eat, a ...
Choose the correct answer to fill the given blank
She _____ to the gym three times a week.
- In each of the following sentences, there is a blank space. Below each such sentence, there are four options with one word each. Fill up the blank with the...
The Chief Justice of India and the chief justices of high courts _________ absolute power in the matter of assigning cases to colleague judges.
...
The declining number of public-transport buses in Kerala has __________ in availability of buses ___________ to approximately 0.50 per 1,000 people, as ...
Sea levels increases ……….. to the …………. of ice caps at the poles.
The call issued by the opposition socialist leader for more federal powers could ____________ tensions.
Recent history casts a remarkably sobering light on how much politicians can count on __________ arguments to hold sway over popular sentiment.
Ankle sprains usually involve the ligaments, muscles, tendons or bones in the area. ____________. The more you sprain your ankle, the greater the chanc...