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.

Related Articles

@ Sign

Pronounced at sign or simply as at, this symbol is used in e-mail addressing to separate the user' name from the user's domain name,...

Munging

(MUHN-jing) Munging (address munging), is the act of altering an email address posted on a Web page to make it unreadable to bots and...

How to Create an RSS Feed

In the second installment of RSS how-to, we look at some of the nonrequired (optional) channel and item tags, discuss RSS specifications in-depth and...

Dictionary Attack

(n.) (1) A method used to break security systems, specifically password-based security systems, in which the attacker systematically tests all possible passwords beginning with...

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...