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.
In a quadrilateral PQRS, the bisectors of ∠R and ∠S intersects each other at point 'O'. Find the ∠Q if ∠P = 75o and ∠ROS = 95...
Angles of a triangle are in the ratio 2 : 3 : 7. Find the difference between the largest and smallest angle of the triangle.
If G is the centroid and AD, BE, CF are three medians of ∆AGF with area 11 cm 2 , then the area of ∆ABC is?
If the ratio of areas of two similar triangles is 4:9, then the ratio of their corresponding sides is?
A triangular field has sides measuring 50 m, 78 m, and 112 m. Determine the height of the field corresponding to the longest side and also find the area...
The sides of a triangle are 10 cm, 17 cm, and 21 cm. Find the area of the triangle using Heron’s formula.
The length of the diagonal of a rectangle is 25 cm, and the ratio of its length to its breadth is 4:3. Find the area of the rectangle.
If the area of ∆ ABC is 30 cm2 & G is the centroid of ∆ ABC.then the area of the ∆ AGB?
If G is the centroid and AD, BE, CF are three medians of ∆BDG with area 6cm 2 , then the area of ∆ABC is?
An angle is equal to 3/7 of its supplement. The angle is :