The impact subclass of parent class constructor or without parameters.

① When there is no parent class constructor with no arguments:

    1) whether or not a subclass constructor parameters;

    . 2) and must be explicitly to subclass constructor super (parameters) to call the parent class constructor forms;

    Otherwise, the following error occurs:

        Implicit super constructor Person() is undefined for default constructor. Must define an explicit constructor

    3) there is a reference in the subclass explicitly call the constructor after super (parameters), if a write constructor with no arguments, the following error occurs:

        Implicit super constructor Person() is undefined. Must explicitly invoke another constructor

. ② superclass no-argument constructor when:

    1) Have subclasses constructor parameters;

    . 2) may also have a constructor parameter; methods in the reference configuration, you can use super explicitly call parent class constructor may not call;

    That is, this time, to create a subclass in the construction method is relatively free.

Summary (additional):

①. When there is no parent class constructor with no arguments, parameters whether or not a subclass constructor must call the parent class constructor with super explicit.

. ② When no parent class constructor with no arguments and a plurality of constructors have parameters, subclasses only a constructor explicitly call parent class;

    Subclasses can also be configured multiple constructors, methods as long as each configuration explicitly call parent class constructor can, to call the parent class constructor which is not a requirement.

. ③ parent class constructor parameters when the presence or absence, presence or absence of subclasses constructor parameter may also have a constructor parameter;

    Super either explicitly by calling the parent class constructor, super may not explicitly call.

Guess you like

Origin www.cnblogs.com/wangffeng293/p/12516910.html