Ace Java 2025: Rock Your 'Thinking in Java' Challenge!

Question: 1 / 510

How are final variables different from constants in Java?

static

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.

Get further explanation with Examzify DeepDiveBeta

final

immutable

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy