-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScope.java
More file actions
26 lines (16 loc) · 456 Bytes
/
Scope.java
File metadata and controls
26 lines (16 loc) · 456 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
package dt;
public class Scope {
public static void main(String[] args) {
int x; // known to all code within main
x = 10;
if (x == 10) { // start new scope
int y = 20; // known only to this block
// x and y both known here.
System.out.println("x and y: " + x + " " + y);
x = y * 2;
}
// y = 100; /*ERROR: y is not known here */
// x is still known here.
System.out.println("x is: " + x);
}
}