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.


How are final variables different from constants in Java?

  1. static

  2. const

  3. final

  4. immutable

The correct answer is: const

The correct keyword to ensure a variable retains its initial value during runtime in Java is "const". Option A, "static", is used to create class variables rather than constant variables. Option C, "final", can be used to create a constant variable, but it allows the value to be changed at runtime using reflection. Option D, "immutable", is not a Java keyword and thus, is incorrect. Therefore, option B is the most suitable keyword for this purpose.