When an object is created, the corresponding constructor is called.
Constructor: used to initialize an object.
Constructor details:
If no constructor is defined in a class, the system adds an empty constructor to the class by default.
After you customize the constructor in the class, the default constructor will no longer exist.
Constructor and general functions are different in writing.
The operation is also different.
The constructor runs as soon as the object is created. Initialize the object.
The general method is executed only when an object is called, and the function of adding an object to an object is provided.
An object is created, and the constructor only runs once,
The general method can be called multiple times by this object.
When can I define constructors?
When analyzing a thing, the thing has some features and the latter behavior, so the content is defined in the constructor.
Construct a code block.
Purpose: initialize the object.
The object runs as soon as it is created and takes precedence over constructor execution.
Difference from constructor:
Construct a code block to initialize all objects in a unified manner,
The constructor initializes the corresponding object.
The constructed code block defines the initialization content that is common to different objects.