Java OCA OCP Practice Question 957

Question

Which of the following are true? (Choose all that apply)

  • A. Encapsulation uses package private instance variables.
  • B. Encapsulation uses private instance variables.
  • C. Encapsulation allows setters.
  • D. Immutability uses package private instance variables.
  • E. Immutability uses private instance variables.
  • F. Immutability allows setters.


B, C, E.

Note

Encapsulation requires using methods to get and set instance variables so other classes are not directly using them.

Instance variables must be private for this to work.

Immutability takes this a step further, allowing only getters, so the instance variables do not change state.




PreviousNext

Related