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 Russian bank has become the first Russian bank to to register with the SEBI as a foreign portfolio investor (FPI)Â Â according to the information...
As per the new guidelines on use of “Beacons”, which vehicles are allowed to use beacons?
Who is set to receive the Satyajit Ray Lifetime Achievement Award at the 54th International Film Festival of India?
Which of the following statements about the World Bank's report on agri-food systems are correct?
A) The report highlights the significant role o...
What is Mukesh Ambani’s rank on the Bloomberg Billionaires Index as of February 8, 2022?
What is the new wage ceiling proposed for EPF contributions as per the government’s plan?
The procurement of goods and services by central public sector enterprises (CPSEs) through Government e-Marketplace (GeM) grew 74 per cent to _______dur...
Recently, former legendary cricketer Heath Streak passed away, he was a former cricketer of which country?
Which of the following statements about the first U . S .- Japan - Philippines trilateral summit is correct?
Consider the following statements regarding the India-UK Migration and Mobility Partnership Agreement (MMPA):
1. The agreement was signed on Ma...