by Dinesh Thakur

When the block is declared without using any modifier, then it is treated as the non-static block is first executed before the constructor is executed. Non-static block directly access the static variable and instance variable.

Here is the Java Example for the program Non-Static Block:

public class NonStatic

{
       NonStatic()
    {
       System.out.println("Dinesh");
    }
      {
         System.out.println("Thakur");
      }
public static void main (String args[])
         {
NonStatic t1=new NonStatic();
         }
}

Non-Static Block in Java Example