A constructor is just a special function.
Lets start from classes. Classes are blueprints for creating objects. You do this by calling new “Class name”
Now lets say you want to make your objects a bit different based on what you give it as parameters when you create it. This is where constructors come in. They can only be called once, and only during object creation.
That is why they are special. Then they use those parameters to fill some fields that are part of your class (or do something else) and that’s that.
Latest Answers