You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+7-5
Original file line number
Diff line number
Diff line change
@@ -2446,21 +2446,23 @@ public class Example {
2446
2446
<b><a href="#related-interview-questions">↥ back to top</a></b>
2447
2447
</div>
2448
2448
2449
-
## Q. What is a compile time constant in Java? What is the risk of using it?
2449
+
## Q. What is a compile time constant in Java?
2450
2450
2451
2451
If a primitive type or a string is defined as a constant and the value is known at compile time, the compiler replaces the constant name everywhere in the code with its value. This is called a compile-time constant.
2452
2452
2453
2453
**Compile time constant must be:**
2454
2454
2455
-
* declared final
2456
-
* primitive or String
2457
-
* initialized within declaration
2458
-
* initialized with constant expression
2455
+
* Declared final
2456
+
* Primitive or String
2457
+
* Initialized within declaration
2458
+
* Initialized with constant expression
2459
2459
2460
2460
They are replaced with actual values at compile time because compiler know their value up-front and also knows that it cannot be changed during run-time.
2461
+
2461
2462
```java
2462
2463
private final int x = 10;
2463
2464
```
2465
+
2464
2466
<div align="right">
2465
2467
<b><a href="#related-interview-questions">↥ back to top</a></b>
0 commit comments