I want to have multiple instances of a class, but be able to change all non-static instances of a variable at once. Maybe this code will be more clear:
public class Example {
public int _x; //_x and _y are NOT static
public int _y;
Example (int x, int y) {
_x = x;
_y = y;
}
public void zeroThem() {
_x = 0;
_y = 0;
}
}
The point of the zeroThem()
method is that I might have
Example A = new Example(1, 2);
Example B = new Example(3, 4);
But once I call something like:
A.zeroThem();
The following will be true:
A._x == 0;
B._x == 0;
A._y == 0;
B._y == 0;
Is there any way to do this without making _x and _y static?