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.
- The average value of the property of Dev, Riya and Tanmay is Rs. 87 lacs. The value of the property of Dev is Rs. 33 lacs less than that of Riya, and Rs. 1...
There are five containers in a truck hold. The weight of the first container is 100 kg and the weight of the second container is 20% higher than the wei...
Sachin Tendulkar's average runs over 40 innings was 52. During his subsequent four innings, he scored 55, 42, 0, and 60 runs. To increase his average to...
A park has an average of 140 visitors on Sundays and 80 on other day. The average number of visitors in a month of 30 days starting with Sunday is
The average income of a group of 30 freelancers is Rs. 500. If 3 freelancers earning an average of Rs. 550 leave the group and 1 freelancer earning Rs. ...
Average weight of all the people in a group is 65 kg. When two people of weight 72 kg and 84 kg left the group, average weight reduces by 1 kg. Find the...
The average age of a group of 9 teachers is 50 years. When the principal retires, the average age of the remaining teachers drops to 45 years. Find the ...
The average age of R, S, T and U is 32 years and the average age of R and S is also 32 years. If U is 4 years older than T, then determine the age of T.
Average of 8 numbers is 50. If average of first four and last two numbers is 40 and 35, respectively then find the fifth number given that ratio of fift...
5 positive numbers are written on a piece of paper. Sum of first 3 numbers is 70 and ratio of the 4th and the 5th number is 2:3. If difference between t...