This repository was archived by the owner on Sep 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFinalVariables.html
More file actions
44 lines (38 loc) · 1.42 KB
/
FinalVariables.html
File metadata and controls
44 lines (38 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html>
<title>Level 2 Final Variables</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://league-level0.github.io/style.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
<script src="https://league-level0.github.io/script/headerAndFooter.js"></script>
<body>
<h2>Final Variables</h2>
<p class="normal">
Sometimes when programming, we want to create variables that never change. <br>
In Java, you can use the keyword <font color="green">final</font> to make sure that your variables can't be changed.<br>
It is a programming convention to make static and final variables <u>all capital letters</u> so that they are easy to identify in your code.<br>
<br>
EXAMPLE:
</p>
<p class="code">
double pi = 3.14159265359;<br>
<br>
pi = 7.7; // This is perfectly valid.<br>
<br>
System.out.println(pi); // This prints out 7.7.<br>
</p>
<p class="normal">
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
</p>
<p class="code">
final double PI = 3.14159265359; //notice we added "final"<br>
<br>
PI = 7.7; //This will cause an error because PI had been labeled as final.<br>
<br>
System.out.println(pi); // It still prints out 3.14159265359.<br>
</p>
<div id="footer">
<script>addFooter();</script>
</div>
</body></html>