父类
package Test;
public class Parent {
private static String s = "abc";
private String o = "def";
static {
System.out.println("Pa static");
}
public Parent() {
System.out.println("Pa cons");
}
{
System.out.println("pa dai");
}
}
子类
package Test;
public class Child extends Parent {
static String s = "chid ad";
String o = "child o";
public Child() {
System.out.println("child con");
}
static {
System.out.println("child static");
}
{
System.out.println("child dai");
}
}
main方法
package Test;
public class Main {
public static void main(String[] args) {
new Child();
}
}
结果
Pa static
child static
pa dai
Pa cons
child dai
child con
结论
- 父类的静态方法 + 静态变量 (书写顺序)
- 子类的静态方法 + 静态变量 (书写顺序)
- 父类的实例代码块
- 父类的成员变量 + 构造方法
- 子类的实例代码块
- 子类的成员变量 + 构造方法