This post will discuss object life cycle.
Know that the word “construct” always refers to object life cycle.
The primary purpose of the constructor is to set up some instance variables to have the proper initial values when the object is created.
The constructor and destructor are optional. The constructor is typically used to set up variables. The destructor is seldom used.
Consider the following class from the last post, but with two new methods.
Most of the methods with double underscores are for code that gets run when certain occurrences happen in the language.
The only time the thing gets destructed is at the end of the program.
The execution of this program is quite simple.
The constructor is a special block of statements when the object is created.
Now, consider having more than one instance.
In the following code, you have two instance variables, a constructor, but no destructor.
The above program will create two independent instances.