Start learning 50% faster. Sign in now
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.
5 girls can do a piece of work in 9 days, 4 boys can do the same piece of work in 8 days, 6 men do the same piece of work in 2 days and 4 women can do t...
'A' operates at 75% of 'B's efficiency, while 'C' functions at 125% of 'B's efficiency. Initially, 'A' and 'B' teamed up for the job and worked for 10 ...
A and B can complete a task together in 12 days, while B alone takes 24 days to finish it. A began working alone and left after ‘x’ days, after whic...
A alone can complete 60% of a work in 36 days while B takes 30 days more than A to complete it. If B and C together can complete the work in 40 days, th...
Find the value of "w" if Armaan can complete a Sales target in (w + 20) days, Malik can complete it in (w + 44) days, and when they work together, they ...
Eight men and five boys together earn ₹3,240 in 6 days. Meanwhile, three men and two boys working together take 12 days to earn ₹2,484. How many day...
Anil and Ashish receive Rs.1400 for work of 7 days. If Anil is 4 times efficient than Ashish, then find the daily wage received by Ashish.
‘A’ can do a piece of work in 10 days. ‘B’ can do 80% of the same work in 12 days. If they work together for the entire time and get paid Rs.120...
Ten men begin to do work. But after some days, four of them left the job. As a result, the job that could have been completed in 40 days is completed in...
P and Q can separately finish the work in 15 days and 25 days respectively. They worked together and P left the work, so Q complete the remaining work i...