Home > DeveloperSection > Interviews > What is static block?

Posted on    March-27-2015 12:11 AM

 Java Java 
 1 Answer(s)
  525  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Posted on    March-27-2015 1:27 AM

1. Is used to initialize the static data member.
2. It is executed before main method at the time of classloading.

class A2{  
  static{System.out.println("static block is invoked");}  
  public static void main(String args[]){  
   System.out.println("Hello main");  

Output:static block is invoked
            Hello main

Don't want to miss updates? Please click the below button!

Follow MindStick