Skip to content

Commit 5a2db0e

Browse files
committed
Example of Scoping
1 parent 02d5252 commit 5a2db0e

4 files changed

Lines changed: 33 additions & 3 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package Assignments;
1+
package Functions;
22

33
import java.util.Arrays;
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package Assignments;
1+
package Functions;
22

33
public class Methods {
44

‎src/Functions/Scope.java‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package Functions;
2+
3+
public class Scope {
4+
public static void main(String[] args) {
5+
int a = 10;
6+
int b = 20;
7+
8+
//Anything that is initialised outside the block can be modified inside the block
9+
//Anything that is initialised inside the block can be initialised again outside the block
10+
11+
//Block. Values Initialised in this block will remain in this Block.
12+
int c;
13+
{
14+
c = 100;
15+
}
16+
System.out.println(c);
17+
18+
//Scoping in For Loops
19+
for (int i = 0; i < 20; i++) {
20+
System.out.println(i);
21+
}
22+
// System.out.println(i);
23+
}
24+
25+
static void sum(int marks){
26+
int num = 60;
27+
System.out.println(num);
28+
System.out.println(marks);
29+
}
30+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package Assignments;
1+
package Functions;
22

33
public class Swap {
44
public static void main(String[] args) {

0 commit comments

Comments
 (0)