I am still fairly junior for all the certs I hold.
Please correct me where I am wrong. The reason a constructor can set the value of final member is that the constructor is called at a special phase of instance construction. Since the instance is being constructed the constructor can initialize the member to a new value.
I seem to recollect that constructors are not methods.
CIAO Peter M. Cooke
Joined: May 11, 2005
Hi Peter The only reason that a constructor can set the value of a final variable is that is has has not been assigned a value upon declaration. Hence if, as like in the test answer, the reference is given null then the constructor would not be able to reassign it eg
Hence the constructor cannot set it if its already set at declaration.
So what im saying is that
is OK only because buf is actually blank (NOT NULL) after declaration, where as the test answer indicates it is actually initialized to null