LearnFrenzy
Sign in Take a free test

Static and Final Keywords · Find the Error · Question 5

Error: a static final field never assigned Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

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

Main.java
public class Main {
    static final String APP_NAME;

    public static void main(String[] args) {
        System.out.println("running");
    }
}
  • A String cannot be static
  • B A blank static final field must be assigned in its declaration or in a static block Correct
  • C main must print APP_NAME
  • D final fields must be private
Correct Answer: Option B

Add = "LearnFrenzy" or a static { APP_NAME = …; } block.

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