java中当static块和构造函数同时出现,顺序是?
静态块先于构造函数执行
class Student {
int age;
String name;
static int count;
public Student() {
System.out.println("in constructor");
}
/*只执行一次。*/
static {
System.out.println("hello");
count = 0;
}
}
public class Test {
public static void main(String[] args) {
Student s = new Student();
Student s1 = new Student();
}
}
更多内容请见原文,文章转载自:https://blog.csdn.net/qq_44639795/article/details/103129412