在不看答案之前,先猜测一下答案吧!
package com.company;
class ParentClass {
public ParentClass() {
System.out.println("父类无参构造代码块 ");
}
public ParentClass(String name) {
System.out.println("父类有参构造代码块 " + name);
}
{
System.out.println("父类构造代码块 ");
}
static {
System.out.println("父类静态代码块 ");
}
}
public class SubClass extends ParentClass {
public SubClass() {
System.out.println("子类无参构造代码块 ");
}
public SubClass(String name) {
System.out.println("子类有参构造代码块 " + name);
}
{
System.out.println("子类构造代码块");
}
static {
System.out.println("子类静态代码块");
}
public static void main(String[] args) {
System.out.println("-------main start-------");
new SubClass("张三");
System.out.println("-------main end-------");