Originally posted by mrudul joshi: Hey, I just checked it in a program code. It is giving a compile time error. But I dont know why is it not getting initialized!
Final instance variables must be initialized by the time the constructor completes. Otherwise, a compiler error occurs. That means, primitives get their values and references point to either real objects on the heap or null. Instance finals can be assigned either where they are declared, or inside the constructors, or inside the instance initializer blocks. To trace the flow of assignment gets trickier when there're several constructors calling each other thru this(). In such a case, make sure that every constructor allows for the finals to become initialized. A special case of final variables initialization is class finals (static fields). They need to be either initialized where they are declared or assigned inside static initializer blocks. Constructors won't do it since, well, these fields have nothing to do with the class instance. Here's a piece of valid code to demo the concept: