DRAFT
Observed
A private field cannot be changed
Even a private field can be mutable
Accessibility (private
) and changability (final
) are two orthogonal concepts. private
means that code in other classes cannot access (read or write) that field. final
means that the field cannot be changed (written) after initialization.
So, the following code works (the code in method m
can modify the field f
):
class A {
private int f;
A() {
f = 19;
}
void m() {
this.f = 9;
}
}
And this works, too (method m
can even modify field f
in another object of class A
):
class A {
private int f;
A() {
f = 19;
}
void m(A a) {
a.f = 9;
}
}