aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes final variable initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "final variable initialization" Watch "final variable initialization" New topic
Author

final variable initialization

reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287


Can someone explain why the compiler is complaining final variable might not being initialzed yet?

thanks.


SCJA, SCJP5.0, SCBCD, SCWCD
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Final variables must be initialized either at the time of declaration or before the constructor of the class holding the final variable, completes.
So in your code you are not initilizing the final variable in the constructor with ini param [ c(int i) ]. Hence the compiler error.
[ June 28, 2005: Message edited by: Srinivasa Raghavan ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
siva prakash
Ranch Hand

Joined: Aug 24, 2004
Posts: 80
Hi,

value to final variable can be assigned at intialization block also

ex :--

public class Test {

final String st ;

{
st = "hello" ;
}

Test() { }

}


With Regards,
Siva
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: final variable initialization
 
Similar Threads
final keyword
is this final variable modified
final variable
when the block code is execute?