1.HelloA.java
public class HelloA {
public HelloA(){
System.out.println("HelloA");
}
{
System.out.println("I'm A class");
}
static {
System.out.println("static a");
}
}
2.HelloB.java
package hao1;
public class HelloB extends HelloA{
public HelloB(){
System.out.println("HelloB");
}
{
System.out.println("I'm B class");
}
static {
System.out.println("static B");
}
public static void main(String[] atgs){
new HelloB();
}
}
3.结果
static a
static B
I’m A class
HelloA
I’m B class
HelloB