LearnFrenzy
Sign in Take a free test

Static and Final Keywords · Find the Error · Question 2

Error: reassigning a final local variable Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

The program below does not compile. Which statement correctly describes the problem?

Main.java
public class Main {
    public static void main(String[] args) {
        final double rate = 7.5;
        rate = 8.0;
        System.out.println(rate);
    }
}
  • A double cannot be final
  • B rate is final and already assigned, so it cannot be assigned again Correct
  • C final variables must be static
  • D 8.0 must be 8.0f
Correct Answer: Option B

Remove final if the value really needs to change.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links