2011-06-23 50 views

回答

0

非静态块将执行初始化。一个静态块只能执行一次。

构造函数将在对象实例化时执行。

当实例化对象时,将执行一个静态块。

这将取决于您的语言。

对于Java,静态块将始终首先执行,然后是非静态块,然后是构造函数。

public class Q20 {  
static int i;  
int j;  
static {  
System.out.println("static block");  
}  
{ 
System.out.println("non static block"); 
}  

public Q20() {  
System.out.println("constructor");  
}  

public static void main(String args[]) {  
Q20 q = new Q20();   
} 
} 

静块

非静块

构造