class Student{
static {
System.out.println("这是在Stduent类中的静态代码块"); // 1
}
{
System.out.println("这是在Student类中构造代码块"); // 2
}
Student(){
System.out.println("这是在Student类中的无参构造的方法"); // 3
}
}
// 4 5 1 2 3
public class StudentDemo {
static {
System.out.println("这是在StudentDemo中的静态代码块"); // 4
}
public static void main(String[] args) {
System.out.println("进入到main方法"); // 5
Student s = new Student();
}
}
class X {
Y b = new Y();
X() {
System.out.print("X");
}
}
class Y {
Y() {
System.out.print("Y");
}
}
public class Z extends X {
Y y = new Y();
Z() {
// super();
System.out.print("Z");
}
public static void main(String[] args) {
new Z();
}
}
// 看程序写结果:
// Y X Y Z