by Dinesh Thakur Category: Data Type

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

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content