Question
Which of the following best illustrates Encapsulation
in Object-Oriented Programming?Solution
Encapsulation is a key OOP principle that involves combining data (fields) and methods (functions) into a single unit (class) and controlling access to them using access modifiers like private, protected, and public. For instance, a BankAccount class might hide its balance field (using private access) and expose methods like deposit() and withdraw() to manipulate it. Encapsulation ensures data integrity and security , preventing unauthorized access or modifications. Why Other Options Are Incorrect : 2. Allowing multiple objects to interact through message passing : This describes Message Passing , which focuses on communication between objects. 3. Hiding complex implementation details from the user : This is Abstraction , not Encapsulation. 4. Enabling a class to inherit properties and methods from another class : This refers to Inheritance , unrelated to Encapsulation. 5. Defining a one-to-many relationship between objects : This aligns with Aggregation or Composition , not Encapsulation.
Rohit's current age matches Rahul's age from 5 years earlier. If the age of Rohit 10 years from now will be the same as Rahul's age 5 years from now, wh...
The heights (in cm) of 9 basketball players in a tournament are as follows: 178, 182, 175, 180, 184, 179, 177, 181, 183
Find the median height of...
Sohan's father was 32 years old when he was born while his mother was 28 years old when his brother, who is two years younger than him, was born. What i...
Present age of βAβ is 40% more than that of βBβ. If 11 years hence from now, βBβ will be 5 years younger than βAβ, then find the sum of ...
A father is three times as old as his son. After 5 years, the fatherβs age will be twice that of his son. What are their current ages?
B is 2 years older than A and A is 5 years older than C. If the sum of the age of A and C is 25 years, then find the sum of the ages of all three.Β
Present age of βAβ is 50% more than that of βBβ. If 12 years hence from now, βBβ will be 11 years younger than βAβ, then find the sum of...
Present ages of βKβ and βLβ are in the ratio 14:6, respectively. If βtβ years hence from now, βKβ will be twice as old as βLβ, then ...
7 years ago, the age ratio between βMβ and βNβ was 4:5. Present average age of βMβ and βOβ is 70 years. Determine the current age of β...
Three individuals β Ria, Tia, and Mia β are discussing their ages. The age of Ria 8 years ago was one-third of Tiaβs age 4 years from now. The tot...