WHAT IS STATIC BLOCK?

Samuel Fernandes

Total Post:38

Points:190
Posted by  Samuel Fernandes
Java 
 558  View(s)
Ratings:
Rate this:
  1. Mayank Tripathi

    Post:807

    Points:4035
    What is static block?


    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


Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!