how it is working ??? as we know that final member variable of type int has no default value , it need to be explicitly assigned the value at the time of declaration or in the constructor of the class.
Golden rule regarding default values of fields is::
If no intialization is provided for an instance variable either in the declaration or in constructor or in instance initiatlizer block then it is automatically initialized with the default value of its type when the class is instantiated.
So in above program, the instance variable is initialized with default value = 0.(int default value)
In this constructor you are assiging the value to the logLevel . before this you are not using it thats why is not giving you the error otherwise it will give you the error The blank final field logLevel may not have been initialized
Cleared SCJP 1.5 | Cleared SCWCD 5.0
SCBCD in progress.....
Joined: Jul 07, 2008
thanks guys, i didn't read it correctly
Arun Krishnan Nair
Joined: Aug 14, 2008
Why the variable logLevel is declared as final?
SCJP 5 - 100%
Aiming for SCBCD 5 & SCWCD 5
Joined: Sep 03, 2008
hi.... i just faced the same problem of declaring final variables... we have to initiaze at the same time as well as the same line where it is declared..otherwise it eill give the compiler error...the variable might not have been initialised....