static block in java java stack block static block stack block java static block in java class use of static block in java static initialization block java class static block java static initializer block static block in java example
static Block in java class example java static initializer block example static code block in java class static block in java code static block in java execution static block in java tutorial static block in java with example static block in java execution flow static code block in java significance of static block in java
Static Block :
Static block is execution is started when any class
contains static block then static block
is loaded into memory.
That means before the main method is called static block
is used for Initialization of static
members.Static block is not inside any method and this block will
get executed only once
while loading the class.
Example :
public class SBDemo {
static{
System.out.println("this is static block");
}
public static void
main(String args[]){
System.out.println(“this is main method”);
}
}
Analysis:
From the above
program we can say that static block execution would take first then it
will
execute or initialize the data members in main method. Then if we run this
program first it
will print this is
static block then it will print this
is main method.
Static block in java
ReplyDeleteThanks for sharing this post, really this post is very simple and easy.