Question:

Which keyword is used to define a constant in Java?

Show Hint

The convention in Java for naming constants (variables declared as `public static final`) is to use all uppercase letters, with words separated by underscores, like `MAX_VALUE`.
Updated On: Jul 2, 2026
  • final
  • const
  • static
  • volatile
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

In Java, the `final` keyword is used to create constants. The `final` modifier can be applied to variables, methods, and classes, with different meanings for each.
When applied to a variable, the `final` keyword means that the variable's value cannot be changed after it has been initialized. It effectively makes the variable a constant.
Example: `final double PI = 3.14159;`
Let's analyze the other keywords:
(B) `const`: While `const` is a reserved keyword in Java, it is not used and has no function. It was likely reserved to avoid confusion for C++ programmers.
(C) `static`: The `static` keyword indicates that a member belongs to the class itself, rather than to an instance of the class. It is often used together with `final` to create a class-level constant (e.g., `public static final int MAX_USERS = 100;`).
(D) `volatile`: The `volatile` keyword is used in concurrent programming to ensure that a variable's value is always read from main memory and not from a thread's local cache.
Therefore, `final` is the keyword used to define a constant.
Was this answer helpful?
0
0