Programming FundamentalsBeginner
Constructor
Pronunciationkun-STRUK-ter
Definition
A special method in object-oriented programming that runs automatically when a new class instance is created, usually used to set initial property values.
Where you hear it
In object-oriented programming discussions, when talking about class initialization, or during code reviews.
Examples
The
Userclass has a constructor that accepts an email and password.Make sure to call the parent constructor using
super()inside your subclass.
Common mistake
Thinking a constructor returns a value, whereas its purpose is to initialize the object rather than return it.
Keep exploring
More in Programming Fundamentals