Sunday, October 24, 2010

static blocks in java

HI,
        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:

AWS certification question

AWS AWS Hi! this is for questions related to AWS questions. EC2 instances EC2 storage types cold HDD : 1. Defines performance in terms...