class a {
{
System.out.println("a构造代码块");
}
static{
System.out.println("a静态代码块");
}
public a() {
System.out.println("a构造函数");
}
void hh(){
System.out.println("a普通方法");
}
}
class b extends a {
public b() {
System.out.println("b构造函数");
}
static{
System.out.println("b静态代码块");
}
{
System.out.println("b构造代码块");
}
void hh(){
System.out.println("b普通方法");
}
}
public class Shunxu {
public static void main(String[] args) {
a aa = new b();
System.out.println("-------分割线----");
new b();
}
}
输出结果:
a静态代码块
b静态代码块
a构造代码块
a构造函数
b构造代码块
b构造函数
-------分割线----
a构造代码块
a构造函数
b构造代码块
b构造函数