Skip to content

Commit c99ea00

Browse files
Rename static_method.java to static_block_method.java
1 parent a42265c commit c99ea00

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

class/static_block_method.java

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
public class Main
3+
{
4+
static int a=3;
5+
static int b;
6+
7+
static void meth(int x)
8+
{
9+
System.out.println("x is"+x);
10+
System.out.println("a is"+a);
11+
System.out.println("b is "+b);
12+
}
13+
14+
static
15+
{
16+
System.out.println("static block initialized");
17+
b=a*2;
18+
19+
}
20+
21+
public static void main(String[] args)
22+
{
23+
meth(42);
24+
}
25+
}
26+
/*
27+
here first the class main is loaded and
28+
second then static block is executed.
29+
third then main is called in the program
30+
if you observe output is:
31+
32+
static block initialized
33+
x is42
34+
a is3
35+
b is 6
36+
*/

0 commit comments

Comments
 (0)