Encapsulation
6.How does encapsulation support abstraction?
-
A. By allowing direct access to all object data
-
B. By hiding implementation details and exposing only necessary functionalities
-
C. By making all methods static
-
D. By enforcing multiple inheritance
By hiding implementation details and exposing only necessary functionalities
By hiding implementation details and exposing only necessary functionalities
7.What happens if a class does not follow the principles of encapsulation?
-
A. It improves code security
-
B. It allows unwanted modifications to object state
-
C. It makes debugging easier
-
D. It ensures proper inheritance
It allows unwanted modifications to object state
It allows unwanted modifications to object state
8.Which of the following is NOT a benefit of encapsulation?
-
A. Data security
-
B. Code reusability
-
C. Unrestricted data access
-
D. Better code maintainability
Unrestricted data access
Unrestricted data access
9.Why should a setter method be used cautiously in an encapsulated class?
-
A. It may allow unintended modifications if not validated properly
-
B. It prevents access to the variable
-
C. It slows down method execution
-
D. It makes the variable static
It may allow unintended modifications if not validated properly
It may allow unintended modifications if not validated properly
10.What is the effect of encapsulation on code reusability?
-
A. It reduces reusability by restricting access to methods
-
B. It increases reusability by providing a controlled interface
-
C. It eliminates the need for abstraction
-
D. It forces all classes to be public
It increases reusability by providing a controlled interface
It increases reusability by providing a controlled interface