Why do we declare private fields when we have accessors and mutators? [duplicate]
问题 This question already has answers here : Why are getter and setter method important in java? [duplicate] (6 answers) Closed 4 years ago . If I create a class in Java, I've always been taught that the convention is to make all fields of a class private. If I need to access or change them, I can create an accessor and mutator method. I do understand the importance of private variables, as they help reduce complexity and allow for encapsulation. What I don't understand is that if I create a