-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12_Scope.java
More file actions
34 lines (24 loc) · 871 Bytes
/
12_Scope.java
File metadata and controls
34 lines (24 loc) · 871 Bytes
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
import java.util.*;
class Solution {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
// local variable must be initialised or if not initialised must
// not be accessed.
int i;
// Compile time error: We cannot access an uninitialised local variable.
// System.out.println(i);
}
}
class Solution1 {
// Constant variable : Use keyword 'final';
// const variable must be initialised.
final int i = 21;
final int j = 15;
// int final j = 15; : We cannot interchange data type and integer.
// final int k; : throw error since we are not initialising a const var.
public static void main(String args[]){
// Scanner sc = new Scanner(System.in);
System.out.println(new Solution().i);
System.out.println(new Solution().j);
}
}