-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaticExp.java
More file actions
38 lines (36 loc) · 1.2 KB
/
Copy pathStaticExp.java
File metadata and controls
38 lines (36 loc) · 1.2 KB
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
35
36
37
38
/*the first static block runs which one is defined in the class in which main method is defined
In this example one static block is defined in the StaticExp class which holds the main method
so that static block will execute first then main method run and in main method the first SOP run
then object creation happen then Student11 class load and then the second static block will execute
no matter there is a static block in other class, the first static block execute which is
defined in main class which holds the main method
Execution flow->
1) static variable initialisation
2) static block
3) static method
4) non-static variable initialisation
5) java block
6) constructor
7) non-static method or normal method
*/
class Student11
{
static {
System.out.println("Static Block Student");
}
{
System.out.println("Java Block");
}
Student11(){
System.out.println("Constructor");
}
}
class StaticExp {
static {
System.out.println("Static Block main class");
}
public static void main(String[] args) {
System.out.println("Main method");
Student11 s=new Student11();
}
}