File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Complie time Constant - final int a; a =1 ; IS NOT?! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Complie time Constant - final int a; a =1 ; IS NOT?!" Watch "Complie time Constant - final int a; a =1 ; IS NOT?!" New topic
Author

Complie time Constant - final int a; a =1 ; IS NOT?!

Ajay Chandravadiya
Greenhorn

Joined: Aug 06, 2007
Posts: 27
Hi,
As per the book and the compiler following is true.



Q. Why 'b' variable is NOT a Compile Time Constant?


SCJP Tiger Hunter 91%.
ahmed yehia
Ranch Hand

Joined: Apr 22, 2006
Posts: 424
The rule for a 'case' is compile- time constants, and variable 'b' isnt considered so, its assigned a value later hence not become compile time constant.
You would have to declare and inialize the final variable in 1 line, like this:
Lucky J Verma
Ranch Hand

Joined: Apr 11, 2007
Posts: 278
variable a is given value at compilation time only so its compile time constant
but variable b is not getting any value till it runs.so run time value assigned.
so not comiple time constant
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Complie time Constant - final int a; a =1 ; IS NOT?!