
Jen Q.
asked 06/26/17Trouble with a code segment in Java
What's wrong with the following code segment?
final double TAX_RATE = 0.08;
TAX_RATE = 0.0875;
final double TAX_RATE = 0.08;
TAX_RATE = 0.0875;
This question is confusing. When I copy this into my Java IDE, it can't compile and i'm left with an error "Cannot assign value to final variable TAX_RATE"
More
1 Expert Answer

Valerie T. answered 09/14/17
Tutor
5.0
(100)
Software Engineer Gone Tutor
In case you're unable to find a clear answer to what "final" means, here's a [hopefully] simple breakdown of why the code won't compile.
The variable is marked as final by having the keyword "final" in front of it. This means you may only assign the value one time at most, and never again. On the first line, you assigned a value of "0.08", and on the next line you tried to re-assign it a value of "0.0875". If you want to be able to re-assign a variable's value, you simply need to remove the word "final" in front.
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Tim C.
06/26/17