java 继承的执行顺序,接下来我们通过代码详解
父类
package com.pingan.com;
public class Father {
RandClass r = new RandClass("father");
static
{
System.out.println("this is father static");
}
{
System.out.println("this is father constructor code");
}
public Father() {
System.out.println("this is father constructor");
}
}
子类
package com.pingan.com;
public class Child extends Father{
RandClass r = new RandClass("child");
static
{
System.out.println("this is child static");
}
{
System.out.println("this is child constructor code");
}
public Child() {
System.out.println("this is child constructor");
}
}
package com.pingan.com;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Child child = new Child();
}
}
运行结果
th