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.
Which of the following banks has launched “Salute Doctors” on the National Doctors Day which is held on 1st July every year?
Who assassinated Michael O'Dwyer to avenge the Jallianwala Bagh Massacre?
Consider the following statements in relation to Biosphere Reserves:
1. Initiated by UNESCO in 1973-74 under its Man and Biosphere (MAB) Programm...
Which one of the following Islands, is known as ‘rice bowl’ of Japan?
Which organization developed the 'Akashteer Air Defence System'?
Which of the following is not correct about ARR method?
Miraj, known for its GI-tagged 'Sitars' and 'Tanpuras,' is in which Indian state?
In regards to Mountains in Uttarakhand, which of the following is not correctly matched?
Which type of soil is known for providing valuable building material?
The Equator is an imaginary line which passes through which of the following countries?
a) Uganda
b) San Sao Tome and Príncipe
c) ...