A block as a group of statements that are collected together called a compound statement. It is bound by opening and closing braces { }. A class definition is contained in a block. A block statement can be nested withing another block. In Java source code, block statements are executed first, then constructor statements are executed, and then method statements are executed.
Best Example:
public class BlockTest{
public String info;
public BlockTest(){
info = ”Constructor:Executed in 2nd step”;
System.out.println(info);
}
{
info = ”Block:Executed in 1st step”;
System.out.println(info);
}
public void show(){
info = ”Method:Executed in 3rd step”;
System.out.println(info);
}
public static void main(String[]args){
BlockTest bt = new BlockTest();
bt.show();
}
}