We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a42265c commit c99ea00Copy full SHA for c99ea00
class/static_block_method.java
@@ -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