Harikrishna Gorrepati wrote:Let me change the code..With this, there is no error. I am getting the error in 2 cases when final variable is NOT initialized with any value
1. declared constructor
2. try to get value from final variable (It is not taking default value i.e., 0)
Why ??
The final variable should be initialized in the same line, which were declared. Otherwise,
you should initialize that variable in every Constructors or one of the instance initializer. Because, the final variable can be initialized only once. If it takes the default value, and because of the final, the value can't be changed in the future. So, this is non-sense. That's why, they don't get initialized with default value as like other non final instance variables.