In a review for certification, I came across the following code:
public class Initializer {
static int si = 10;
int i;
final boolean bool;
}
It generates compilation error in the declaration of variable final boolean bool
, since it was not initialized.
Note that the variable int i
has not been initialized either, but it does not have any problem since the (non-final?) Instance variables are implicitly initialized.
But why, why is this differentiation with final
and is it mandatory to initialize a final variable when an instance is built?