[Java Basics] 4. The implicit call of the constructor

Article Directory

to sum up

1. When a class does not have a custom constructor, a parameterless constructor (implicit) will be generated.

2. Each class will call the parent class's parameterless constructor (implicit) in front of its constructor. When the subclass does not have a custom constructor, a no-parameter constructor is implicitly generated, and the parent class's no-parameter constructor is called in the constructor. When the parent class does not have a parameterless constructor, the parameterized constructor of the parent class must be called explicitly.

3. You can add super to the first line of the constructor to call the parent class constructor (explicit). After an explicit call, it will no longer be called implicitly (similar to the automatically generated constructor, when there is an explicit call, it will not be called implicitly again).

Guess you like

Origin blog.csdn.net/qq_43621091/article/details/114032330