What is the purpose of access modifiers?
问题 I know this applies to many languages, and not just Java, but that is the language I'm most familiar with. I understand what the modifiers do, and how to use them. I just want to know, why do we need them? Why can't every object be accessible, whether or not it needs to be? 回答1: The reason becomes more apparent when you have to maintain a larger project. When a method or variable is public, you have to be careful when you make changes to it, because you never know which parts of the codebase