Showing posts with label Static Block. Show all posts
Showing posts with label Static Block. Show all posts

Wednesday, May 28, 2014

Static Block

Note- Main method will always execute, after execution of all the static blocks which are there in the class.

Ex-

public class StaticBlock{
    public static void main(String[] args){
        System.out.println("Main method will always execute, after execution of all the static blocks which are there in the class.");
    }
    static{
        System.out.println("1st This will execute before main method");
    }
    static{
        System.out.println("2nd This will execute before main method");
    }
}

Output
1st This will execute before main method
2nd This will execute before main method
Main method will always execute, after execution of all the static blocks which are there in the class.