my dog learned polymorphism*
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 Android Security Essentials Live Lessons this week in the Android 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
 
Consider Paul's rocket mass heater.
 
subject: Complie time Constant - final int a; a =1 ; IS NOT?!
 
Similar Threads
switch case with final
switch question
Swtich Statement
what is compile time constant in switch case?
compile time constant