...
Consequently, invocation of an overridable method during object construction may cause result in the use of uninitialized data, leading to runtime exceptions or to unanticipated outcomes. Calling overridable methods from constructors can also leak the this
reference before object construction is complete, potentially exposing uninitialized or inconsistent data to other threads. See guideline TSM01-J. Do not let the (this) reference escape during object construction for additional information.
...
The doLogic()
method is invoked from the superclass's constructor. When the superclass is constructed directly, the doLogic()
method in the superclass is invoked and executes successfully. However, when the subclass initiates the super class's construction, the subclassessubclass' doLogic()
method is invoked instead. In this case, the value of color
is still null
because the subclasses subclass' constructor has not yet concluded.
...