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.
Where was the Urban Co-operative Bank (UCB) situated, whose license was cancelled by the Reserve Bank of India (RBI) in Dec 2023?
Who was the first woman to receive the Arjuna award for Hockey?
Which of the following is a risk associated with implementation of green revolution in India?
I. It would Possibly increase the disparities betwe...
Which gas is responsible for the blue color of the Earth’s atmosphere?
Match the following states with their respective ranks at the Khelo India Youth Game 2023 and choose the correct code.
States Their Ranks
...
Who is the promoter of Funskool India Ltd., a company that has acquired the licence to manufacture and distribute action figures of Chhota Bheem and fri...
What is the minimum net worth of SRO Fintech?
Find a single discount percentage equivalent to successive discounts of 20%, 30%, and 35% ?
On May 23, 2023, who assumed the position of Chairperson at the Competition Commission of India?
The maiden international cruise vessel between Chennai and Sri Lanka was flagged off by the Union Minister of Ports, Shipping and Waterways Sarbananda ...