Question
A software developer is designing a banking application
where each bank account object should restrict direct access to its balance variable to prevent accidental modifications. Instead, the application allows access to the balance only through specific methods like getBalance() and deposit(), which include validation checks to ensure that operations are secure and valid. Which object-oriented programming principle is the developer applying to achieve this data protection?ΒSolution
Encapsulation is a core principle of object-oriented programming that the developer is applying here to protect the bank accountβs internal state, specifically its balance. By restricting direct access to the balance variable, the developer ensures that this data can only be modified through predefined methods such as deposit() and getBalance(). These methods act as controlled access points, which not only prevent unauthorized modifications but also allow for validation checks to maintain the integrity of the data. Encapsulation combines data (variables) and methods (functions) within a class, creating a well-defined boundary that prevents external classes from directly accessing or altering the internal state. This approach improves security and data integrity, making the code easier to maintain and less prone to errors. The other options are incorrect for the following reasons: β’ Option 1 (Abstraction) focuses on simplifying complex systems by hiding unnecessary details and providing a clean interface, but it does not inherently control access to an object's internal state. β’ Option 3 (Inheritance) allows a new class to inherit properties and behaviors from an existing class, which helps with code reuse but does not inherently involve data hiding or restricting access to internal states. β’ Option 4 (Polymorphism) enables objects of different classes to be treated as instances of a common superclass, allowing flexible and dynamic code. However, it does not relate to the control or protection of internal data. β’ Option 5 (Aggregation) represents a "has-a" relationship between objects, where one class contains instances of another class as part of its state. It describes object relationships rather than protecting or hiding internal data within an object.
What will come in the place of the question mark (?) in the following equation, if β+β and βββ are interchanged and βΓβ and βΓ·β are ...
In a certain code language, 'TEACHER' is written as 'CAHEETR', and 'STUDENT' is written as 'DUETNST'. How will 'SUCCESS' be written in that language?
In a certain code language, '274' means 'you are fool', '137' means 'Rohan is fool', and '893' means 'Riya likes Rohan'.
Which of the following o...
In a certain code language,
βA + Bβ means βA is the son of Bβ,
βA β Bβ means βA is the sister of Bβ,
βA Γ Bβ...
Select the option in which the number-pair does NOT share the same relationship as that shared by the given number-pair.
7 : 216
Study the given arrangement of 2-digit numbers and symbols and answer the question that follows.
(Left) 65 67 87 86 and 43 32 37 @ 27% 29 76 71 4...
Which of the following numbers will replace the question mark (?) in the given series?
In a certain code language, βBINDβ is coded as β9214β and βDRIBβ is coded as β4109β. What is the code for βNβ in the given code lang...
Which two symbols from amongst the given options should be interchanged to make the given equation correct?
(35 β 2) Γ 3 = (56 Γ 8 Γ· 3 + 100...
Refer to the given letter and symbol series and answer the question that follows.
(Left) S Q β¬ κ¬ G Β₯ F @ X # B β¦ K @ T @ M B # S & S A % L...