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
Jenna Phipps is a writer for Webopedia.com, Enterprise Storage Forum, and CIO Insight. She covers data storage systems and data management, information technology security, and enterprise software solutions.
Get the Free Newsletter
Subscribe to Daily Tech Insider for top news, trends & analysis
This email address is invalid.
Get the Free Newsletter
Subscribe to Daily Tech Insider for top news, trends & analysis
This email address is invalid.

Related Articles

Embedded Analytics

Embedded analytics brings self-service business intelligence to everyday application users.

HRIS

Human resources information system (HRIS) solutions help businesses manage multiple facets of their workforce operations. They provide a central platform for human resources professionals...

Complete List of Cybersecurity Acronyms

Cybersecurity news and best practices are full of acronyms and abbreviations. Without understanding what each one means, it's difficult to comprehend the significance of...

Human Resources Management System

A Human Resources Management System (HRMS) is a software application that supports many functions of a company's Human Resources department, including benefits administration, payroll,...

ScalaHosting

ScalaHosting is a leading managed hosting provider that offers secure, scalable, and affordable...

HRIS

Human resources information system (HRIS) solutions help businesses manage multiple facets of their...

Best Managed Service Providers...

In today's business world, managed services are more critical than ever. They can...