class DemoCodeBlock {
static {
System.out.println("这是主函数的静态代码块");
}
public static void main(String[] args) {
Student s = new Student();
}
}
class Person {
private String name;
private int age ;
public Person() {
System.out.println("这是父类构造方法");
}
public Person(String name,int age) {
this.name = name;
this.age = age ;
System.out.println("这是父类构造方法");
}
static {
System.out.println("这是父类的静态代码块");
}
{
System.out.println("这是父类动态代码块");
}
}
class Student extends Person {
public Student() {
System.out.println("这是子类构造方法");
}
public Student(String name, int age) {
super(name,age);
System.out.println("这是子类构造方法");
}
static {
System.out.println("这是子类静态代码块");
}
{
System.out.println("这是子类动态代码块");
}
}
|
|