In order to preserve encapsulation of an object, we would do all of the following except for which one?


In order to preserve encapsulation of an object, we would do all of the following except for which one?


a) Make the instance data private

b) Define the methods in the class to access and manipulate the instance data

c) Make the methods of the class public

d) Make the class final

e) All of the above preserve encapsulation

Answer: d. Explanation: Encapsulation means that the class contains both the data and the methods needed to manipulate the data. In order to preserve encapsulation properly, the instance data should not be directly accessible from outside of the classes, so the instance data are made private and methods are defined to access and manipulate the instance data. Further, the methods to access and manipulate the instance data are made public so that other classes can use the object. The reserved word “final” is usedto control inheritance and has nothing to do with encapsulation.