Constructor

A constructor initializes an object in object-oriented programming. In many programming languages, a constructor has the same name as the class in which it creates the object. A programmer will typically declare a constructor within the class and then define the data types that make up the ensuing object.

Common types of constructors

Default constructors: what the program automatically inserts if no constructor is defined. This depends on the language, but typically a default constructor sets everything within the new object to its default value (such as 0) and defines no arguments. It can also set default parameters but is still considered a default constructor.

Parameterized constructor: has parameters which identify arguments once a new object is initialized. The program automatically calls a constructor, which a programmer designs with certain parameters.

Copy constructor: creates a new object by making a copy of a preexisting one. Typically these objects must be in the same class.

Conversion constructor: does not have a specific (explicit) declaration; instead, the program implies the declaration. If a constructor is only given one parameter, the program may convert an object to another class or type implicitly. This is also referred to as a converting constructor.

Move constructor: transfers a pointer to different data or assigns the data to another object, instead of using a copy constructor. The data type moves rather than being copied.






Jenna Phipps
Jenna Phipps is a contributor for websites such as Webopedia.com and Enterprise Storage Forum. She writes about information technology security, networking, and data storage. Jenna lives in Nashville, TN.

Top Articles

The Complete List of 1500+ Common Text Abbreviations & Acronyms

From A3 to ZZZ we list 1,559 SMS, online chat, and text abbreviations to help you translate and understand today's texting lingo. Includes Top...

List of Windows Operating System Versions & History [In Order]

The Windows operating system (Windows OS) refers to a family of operating systems developed by Microsoft Corporation. We look at the history of Windows...

How to Create a Website Shortcut on Your Desktop

Website Shortcut on Your Desktop reviewed by Web Webster   This Webopedia guide will show you how to create a website shortcut on your desktop using...

Generations of Computers (1st to 5th)

Reviewed by Web Webster Learn about each of the 5 generations of computers and major technology developments that have led to the computing devices that...

Eventbrite

  Eventbrite is an online event posting, event management, and ticketing website. Eventbrite can...

Docker

Docker is an open-source platform used for developing and running applications by allowing...

Blockchain

Blockchain is one of the core technologies behind cryptocurrency. Blockchain is a system...