Why would you declare getters and setters method private? [duplicate]
问题 This question already has an answer here: Why use getters and setters/accessors? 38 answers I saw a code where getters and setters methods are declared private. I am trying to figure out the logic behind it, and I am really having hard time to understand why would you declare them as private? That's exactly opposite of what we are trying to achieve through getters and setters. 回答1: I can think of several reasons: you want to prevent future public access. If a different programmer sees your