# Which type can cause problems with encapsulation in Java?

Out of the following, which type can cause problems with encapsulation?

A. Int

B. Int[]

C. String

D. non of the above

I chose D and was incorrect. I am kind of confused what this questions is asking about... I just began to learn about the encapsulation and it seems it's just to keep the fields private and not changeable from outside of the class. Why would any type cause problems?

• The only problem that can be caused with encapsulation, is you not implementing the type with the encapsulation ideas in mind. There is no inherent "problem" for any of those types when dealing with encapsulation. In your place, I would ask your teacher what they meant in this question - because - it really is ambiguous (and hence it is expected that you were confused). Nov 22 '21 at 11:41
• @nirshahar Okay! Thanks for the comment. I will keep that in mind. Nov 22 '21 at 19:04

I think it should be (B) because when using implement get method to get the array will be able to change the array even if it's private through the getter because the "get" method will return a reference to the array, not the array itself.