Why it is recommended to declare instance variables as private?
问题 My question relates to Java, but it also can be applied to C#. I was wondering why everybody recommends making the instance variables private as opposed to making them protected . Let's just think about it. Private variables are not seen by the subclass, so if I need to access or change the variables of the superclass in my subclass I am forced to use some accessor and mutators method like getMyPrivateVariable or setMyPrivateVariable . But when you extend some class and inherit its members,