Static code block execution timing

Static variables assigned a default value of zero in the preparation phase, the user assigned value in the initialization phase, static code block is executed in the initialization phase

public  class StaticBlockDemo { 

    static  int A = 2 ; 
    
    static {
         // If the prepare phase = 0 A;
         // if the initialization phase, A = 2; 
        System.out.println (A); 
    } 
    
    public  static  void main ( String [] args) { 
        
    } 
}

 

Guess you like

Origin www.cnblogs.com/heyboom/p/11408448.html