代码块,静态代码块,构造代码块执行顺序
/**
* 代码块
* @author Xu
*
*/
class Student {
static {
System.out.println("Student 静态代码块");// 3
}
{
System.out.println("Student 构造代码块");// 4、6
}
public Student() {
System.out.println("Student 构造方法");// 5、7
}
}
class BlockTest {
static {
System.out.println("Demo2_Student静态代码块");// 1
}
public static void main(String[] args) {
System.out.println("我是main方法");// 2
Student s1 = new Student();
Student s2 = new Student();
}
}
注:代码可粘贴运行