1.在类加载的时候会执行静态程序块(这里没有)
2。new B()的时候先执行父类的构造函数 A(),  所以:AAA
3。B中的doSomething()覆盖了父类方法,因而在A()中的doSomething()调用的是B()中的方法,取的变量还是A的,缺省值 = 0
4。执行B(),剩下的明白了吧!A.doSomething()一直没有运行

解决方案 »

  1.   


    看看<<thinking in java >>吧其中有很详细的介绍/*--by bookbobby(书呆)-+
     |            |
     |  你说爱我只是习惯  |
     |  再也不是喜欢    |
     |  我给你的爱     |
     |  已不再温暖     |
     |            |
     +--by bookbobby(书呆)-*/
      

  2.   

    请仔细研读
    if you call "new Class()":
    First, the memory for the complete object is allocated and the default
    values for the instance variables are assigned(0 or null). 
    Second, the top-level constructor is called and follows these steps 
    recursively down the inheritance tree:
    1. Bind constructor parameters
    2. If explicit this(), call recursively and then skip to step 5
    3. Call recursively the implicit or explicit super(...), except for
       Object because Object has no parent class
    4. Execute explicit instance variable initializers
    5. Execute body of current constructor