结论:
a.父类的静态代码块
b.子类的静态代码块
c.父类的构造代码块
d.父类的构造方法
e.子类的构造代码块
f.子类的构造方法
演示
父类:
package t1;
/**
* Created by Administrator on 2017/6/4.
*/
public class ClassA {
private static String name;
private String pwd;
{
System.out.println("这是父类的构造代码块");
}
static{
name="classA";
System.out.println("这是父类的静态代码块");
}
public ClassA(){
System.out.println("这是父类的构造方法");
}
}
子类
package t1;
/**
* Created by Administrator on 2017/6/4.
*/
public class ClassB extends ClassA{
private static String nameB;
private String pwdB;
{
System.out.println("这是子类的构造代码块");
}
static{
nameB="classB";
System.out.println("这是子类的静态代码块");
}
public ClassB(){
System.out.println("这是子类的构造方法");
}
}
测试方法
package t1;
/**
* Created by Administrator on 2017/6/4.
*/
public class Test {
public static void main (String [] args){
new ClassB();
}
}
结果: