Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Dive into the depths of Java with our quiz based on "Thinking in Java, Fourth Edition" by Bruce Eckel. Test your knowledge, solidify concepts, and prepare for certification with challenging questions and insightful feedback.

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


Which of the following is true for static final fields in Java?

  1. They are considered global variables

  2. They can be modified using reflection

  3. They are compile-time constants

  4. They are initialized at runtime

The correct answer is: They can be modified using reflection

Static final fields in Java are considered global variables, meaning they can be accessed and used in any part of the code. However, option B is incorrect because static final fields cannot be modified using reflection. Reflection is a feature in Java that allows code to inspect and modify itself at runtime, but static final fields cannot be modified once they are initialized, which leads to option C being incorrect. Static final fields are also not initialized at runtime. In fact, they are initialized at compile-time, making option D incorrect. The correct answer, option B, states that static final fields are compile-time constants. This means that they cannot be reassigned or altered after compilation, making them constant values throughout the program. This makes them useful for storing values that should not be changed, such as mathematical constants or configurations.