OCA Java SE 8 Mock Exam Review - OCA Mock Question 36


How to include encapsulation in your class design?

  1. Define instance variables as private.
  2. Define public methods to access and modify the instance variables.
  3. Define the instance variables as public members.
  4. All of the previous.
  5. None of the previous.


A, B


A well-encapsulated class should hide its instance variables from the outside world by accessing and modifying instance variables via the public methods to ensure that the outside world can access only the variables the class allows it to.