constructor
B1Pronunciation
UK
- /kənstrˈʌktə/
US
- /kənˈstrəktər/
Description
- builder
- maker
- assembler
- object-setup method
A constructor isn’t just someone who builds houses. It can mean the person or company responsible for building a project—especially in formal writing about construction. In programming, it means a special method that creates a new object and sets it up.
The word comes from the Latin construere, meaning "to build together." In construction, the constructor brings together workers, tools, and materials to turn plans into a real structure. In programming, the constructor runs when an object is created and gives it its first values. You might read, "The constructor is responsible for site safety," or "This class’s constructor sets a default role for new user profiles."
The word "constructor" most often points to one of two things: building work in the real world, and object creation in programming.
In construction and engineering, a constructor is the person or company that builds a project. In everyday speech you may hear builder or contractor more often, but in contracts, reports, and project documents, "the constructor" can mean the team in charge of doing the building. They plan the work, manage materials and labor, and make sure the project is put together safely and correctly.
In computer science, "constructor" has a more exact meaning: it is a special function or method that runs when you create a new object. Its job is to set the object’s starting state by giving it initial values and doing any required setup. This matters for reliable software; for example, "The Java constructor ensures that every new 'User' object is assigned a unique ID upon creation."
The word comes from the Latin construere, meaning "to build together" (also "to pile up" or "to arrange"). Whether it’s a bridge made from steel and concrete or an object made from data and rules, a constructor is what brings separate parts together into something that works.
Examples
- 1
Java objects
In Java, the constructor runs when you create a new object.
- 2
Overloaded constructors
This class has two constructors: one with no arguments and one that takes a name.
Phrase
with no arguments
without any input values
- 3
Inheritance
The child class must call the parent constructor first.
- 4
Access control
We made the constructor private so users can't create the class directly.
Domain
in programming, private means only usable inside the class
- 5
Setup code
Most of the setup code belongs in the constructor, not in every method.
Forms and spellings
2 forms open this card.
Main spelling
- constructornoun
Forms
- constructorspluralnoun