Which of the following is the correct syntax to declare a constant in Java?
easy📝 Syntax Q3 of 15
Java - Custom Exceptions
Which of the following is the correct syntax to declare a constant in Java?
Aconst int MAX_VALUE = 100;
Bint MAX_VALUE = constant 100;
Cstatic int MAX_VALUE = 100;
Dfinal int MAX_VALUE = 100;
Step-by-Step Solution
Solution:
Step 1: Recall Java constant declaration syntax
Java uses 'final' keyword to declare constants.
Step 2: Check each option
final int MAX_VALUE = 100; uses 'final' correctly. 'const' is not a Java keyword. 'constant' keyword does not exist. 'static' alone doesn't make constant.
Final Answer:
final int MAX_VALUE = 100; -> Option D
Quick Check:
Constant declaration = final keyword [OK]
Quick Trick:Use 'final' keyword to declare constants [OK]
Common Mistakes:
Using 'const' keyword in Java
Forgetting 'final' keyword
Using 'static' alone for constants
Master "Custom Exceptions" in Java
9 interactive learning modes - each teaches the same concept differently