I find the encapsulation concept a bit confusing. So far I have read that the members of the class should be private and any access to private members must be through getter and setter methods, which are public. Are these the only properties which define a properly encapsulated class?

If yes, what about protected class members? We can access protected members in the same package through an object reference — are classes containing protected members improperly encapsulated?

Please give clarification.

没有正确的解决方案

许可以下: CC-BY-SA归因
scroll top