An attribute when declared with the static modifier has the characteristic of "propagating its value" for all instances of the class to which it belongs, ie its value will be the same for all instances. Because of this feature these attributes are named class variables. These have their value stored in a memory fixed address . Here's an example:
class Foo {
public static int count = 0 ;
Foo() {
++count;
}
}
Another use for the static modifier is when we want to make an attribute immutable, unalterable, achieved from the addition of the final modifier, as in the following example:
class Carro {
private static final int RODAS = 4;
...
}
The same result is when we declare the attribute without the static modifier, only with the final modifier.
class Carro {
private final int RODAS = 4;
...
}
In both statements we achieve the same goal, that of making the value of an attribute immutable. Given this, what is the real advantage in using the static modifier in creating immutable variables? Is there any real gain related to performance?