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.
If 1 is added to each even digit and 2 is subtracted from each odd digit in the number 3527468, how many digits will appear more than once in the new nu...
Statements:
All buses are cars.
No jeep is a car.
Conclusions:
I. No car is a jeep.
II. No jeep is a bus.
Nine Persons – C, D, B, A, J, F, G, H and K – are sitting in a straight line facing north, but not necessarily in the same order. G sits second to t...
Select the set in which the numbers are related in the same way as are the numbers of the following sets.
(NOTE : Operations should be performed ...
‘A # B’ means ‘A is the brother of B’.
‘A @ B’ means ‘A is the daughter of B’.
‘A & B’ means ‘A is the husband of B�...
In the following question, select the related letters from the given alternatives.Â
BO : AM :: CP : ?Â
Read the given question and decide which of the following options is required to answer the question?
Question:
Luc...
Select the Venn diagram that best represents the relationship among the given set of classes.
Earth, Country, State
A question is given, followed by two statements labelled I and II. Identify which of the statements is/are sufficient to answer the question.
Qu...
Select the correct combination of mathematical signs to sequentially replace the * signs and to balance the given equation.
17 * 4 * 6 * 2 * 4 = 9