LearnFrenzy
Sign in Take a free test

Static and Final Keywords · Predict the Output · Question 6

Modifying an object through a final reference Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

What is the output of the following Java program?

Main.java
import java.util.ArrayList;
import java.util.List;

public class Main {
    static final List<Integer> SCORES = new ArrayList<>();

    public static void main(String[] args) {
        SCORES.add(90);
        SCORES.add(75);
        SCORES.remove(Integer.valueOf(90));
        SCORES.add(0, 60);
        System.out.println(SCORES + " " + SCORES.size());
    }
}
  • A [60, 75] 2 Correct
  • B [] 0
  • C Compilation error
  • D [90, 75, 60] 3
Correct Answer: Option A

final stops reassigning SCORES, not modifying the list it refers to.

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