《Thinking in java》——多态(1)

    If you call a dynamically-bound method inside a constructor, the overridden definition
that method is used. However, the effect of this call can be rather unexpected because th
overridden method will be called before the object is fully constructed. This can conceal
difficult-to-find bugs.

 

    (在子类中)如果你在构造方法中调用动态绑定的方法(父类中有的方法),就会调用到这个方法的重写方法。然而,这种调用的效果是相当不被期望的,因为重写的方法会在对象完全构造之前被调用,这会掩盖掉很难发现的bugs。

你可能感兴趣的:(java)