一道java基础面试题

package test;

class A {
    public A(){
        System.out.println("A3");
    }
    {
        System.out.println("A1");
    }
    static {
        System.out.println("A2");
    }
}
             
 
public class B extends A {
    public B(){
        System.out.println("B3");
    }
    {
        System.out.println("B1");
    }
    static {
        System.out.println("B2");
    }
 
 
    public static void main(String[] args) {
        A a1=new B();
        B a2=new B();
    }
}

 

有意思。

看输出。

A2
B2
A1
A3
B1
B3
A1
A3
B1
B3

 

posted @ 2016-05-16 17:13  情不知所起一往而深  阅读(146)  评论(0编辑  收藏  举报