What is static block in java ?
Observe the Below program Here:
package newPackage;
public class StaticBlock {
int i;
StaticBlock()
{
System.out.println("Inside Constructor ");
}
static
{
System.out.println(" Inside the static block ");
}
{
System.out.println("Inside the Non static Block ");
}
public static void main(String[] args) {
System.out.println(" Inside the Main Method ");
StaticBlock b = new StaticBlock();
}
}
The output of the above program is as follows :
Inside the static block
Inside the Main Method
Inside the Non static Block
Inside Constructor
No comments:
Post a Comment