Java's parent and child class constructor

Reference: The constructor of the parent class and subclass in java

Each class will have a parameterless structure by default, but if a parameterized structure is provided manually, it will not be provided by default. (This also applies to parent and child classes)
When a subclass of a parent class creates an object, the parent class's no-parameter construction will be used.
Generally, the parameterized structure of the parent class is used for variable initialization.
When the subclass creates a parameterized object,
situation 1: the parent and child class may not provide the parameterless structure, and directly in the subclass parameterized structure spuer("22"); .
Case 2: The parent class provides a parameterless structure, and the subclass only needs to provide a parameterized structure, not a parameterless structure.

Guess you like

Origin blog.csdn.net/weixin_43983411/article/details/108511925