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

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

Master your knowledge of Java programming with our immersive quiz based on 'Thinking in Java'. Test your skills with detailed questions and receive hints and explanations to enhance your learning. Get ready to ace your Java exam!

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.