Protect int, only visible to specified methods

Is there a way that i is not visible to other methods within the same class?

private int i;

private void updateI(int i) {
  this.i = i;
}
Jon Skeet
people
quotationmark

No - all members of a class are visible to each other.

If you find that some members of your class shouldn't be accessing a particular member, that may indicate that you should split your class up - think about whether you could partition the information more finely, basically. That's not always a solution, of course - but certainly if you find that there are two or three fields that are related to each other, and that only some methods should touch, that's often an indication that you should put them in their own type.

people

See more on this question at Stackoverflow