<s>
In	O
class-based	B-Application
,	O
object-oriented	B-Language
programming	I-Language
,	O
a	O
constructor	O
(	O
abbreviation	O
:	O
ctor	O
)	O
is	O
a	O
special	O
type	O
of	O
function	O
called	O
to	O
create	O
an	O
object	O
.	O
</s>
<s>
It	O
prepares	O
the	O
new	O
object	O
for	O
use	O
,	O
often	O
accepting	O
arguments	O
that	O
the	O
constructor	O
uses	O
to	O
set	O
required	O
member	B-Application
variables	I-Application
.	O
</s>
<s>
A	O
constructor	O
resembles	O
an	O
instance	B-Language
method	I-Language
,	O
but	O
it	O
differs	O
from	O
a	O
method	O
in	O
that	O
it	O
has	O
no	O
explicit	O
return	O
type	O
,	O
it	O
is	O
not	O
implicitly	O
inherited	B-Language
and	O
it	O
usually	O
has	O
different	O
rules	O
for	O
scope	O
modifiers	O
.	O
</s>
<s>
They	O
have	O
the	O
task	O
of	O
initializing	O
the	O
object	O
's	O
data	B-Application
members	I-Application
and	O
of	O
establishing	O
the	O
invariant	B-Application
of	I-Application
the	I-Application
class	I-Application
,	O
failing	O
if	O
the	O
invariant	O
is	O
invalid	O
.	O
</s>
<s>
Immutable	B-Application
objects	I-Application
must	O
be	O
initialized	O
in	O
a	O
constructor	O
.	O
</s>
<s>
Most	O
languages	O
allow	O
overloading	B-Language
the	O
constructor	O
in	O
that	O
there	O
can	O
be	O
more	O
than	O
one	O
constructor	O
for	O
a	O
class	O
,	O
with	O
differing	O
parameters	O
.	O
</s>
<s>
Constructors	O
,	O
which	O
concretely	O
use	O
a	O
single	O
class	O
to	O
create	O
objects	O
and	O
return	O
a	O
new	O
instance	O
of	O
the	O
class	O
,	O
are	O
abstracted	O
by	O
factories	B-Application
,	O
which	O
also	O
create	O
objects	O
but	O
can	O
do	O
so	O
in	O
various	O
ways	O
,	O
using	O
multiple	O
classes	O
or	O
different	O
allocation	O
schemes	O
such	O
as	O
an	O
object	O
pool	O
.	O
</s>
<s>
If	O
the	O
programmer	O
does	O
not	O
supply	O
a	O
constructor	O
for	O
an	O
instantiable	O
class	O
,	O
Java	B-Language
compiler	O
inserts	O
a	O
default	O
constructor	O
into	O
your	O
code	O
on	O
your	O
behalf	O
.	O
</s>
<s>
You	O
would	O
not	O
find	O
it	O
in	O
your	O
source	O
code	O
(	O
the	O
java	B-Language
file	O
)	O
as	O
it	O
would	O
be	O
inserted	O
into	O
the	O
code	O
during	O
compilation	O
and	O
exists	O
in	O
.class	O
file	O
.	O
</s>
<s>
It	O
may	O
initialize	O
data	B-Application
members	I-Application
to	O
zero	O
or	O
other	O
same	O
values	O
,	O
or	O
it	O
may	O
do	O
nothing	O
at	O
all	O
.	O
</s>
<s>
In	O
Java	B-Language
,	O
a	O
"	O
default	O
constructor	O
"	O
refer	O
to	O
a	O
nullary	O
constructor	O
that	O
is	O
automatically	O
generated	O
by	O
the	O
compiler	O
if	O
no	O
constructors	O
have	O
been	O
defined	O
for	O
the	O
class	O
or	O
in	O
the	O
absence	O
of	O
any	O
programmer-defined	O
constructors	O
(	O
e.g.	O
</s>
<s>
in	O
Java	B-Language
,	O
the	O
default	O
constructor	O
implicitly	O
calls	O
the	O
superclass	O
's	O
nullary	O
constructor	O
,	O
then	O
executes	O
an	O
empty	O
body	O
)	O
.	O
</s>
<s>
Like	O
C++	B-Language
,	O
Java	B-Language
also	O
supports	O
"	O
Copy	O
Constructor	O
"	O
.	O
</s>
<s>
But	O
,	O
unlike	O
C++	B-Language
,	O
Java	B-Language
does	O
n't	O
create	O
a	O
default	O
copy	O
constructor	O
if	O
you	O
do	O
n't	O
write	O
your	O
own	O
.	O
</s>
<s>
In	O
C++	B-Language
,	O
move	B-Application
constructors	I-Application
take	O
an	O
Rvalue	O
reference	O
to	O
an	O
object	O
of	O
the	O
class	O
,	O
and	O
are	O
used	O
to	O
implement	O
ownership	O
transfer	O
of	O
the	O
parameter	O
object	O
's	O
resources	O
.	O
</s>
<s>
Java	B-Language
,	O
C++	B-Language
,	O
C#	B-Application
,	O
ActionScript	B-Operating_System
,	O
and	O
MATLAB	B-Language
have	O
a	O
naming	O
convention	O
in	O
which	O
constructors	O
have	O
the	O
same	O
name	O
as	O
the	O
class	O
with	O
which	O
they	O
are	O
associated	O
.	O
</s>
<s>
In	O
PHP	B-Application
5	O
,	O
a	O
recommended	O
name	O
for	O
a	O
constructor	O
is	O
__construct	O
.	O
</s>
<s>
Since	O
PHP	B-Application
5.3.3	O
,	O
this	O
works	O
only	O
for	O
non-namespaced	O
classes	O
.	O
</s>
<s>
In	O
PHP	B-Application
7	O
,	O
you	O
should	O
always	O
name	O
the	O
constructor	O
as	O
__construct	O
.	O
</s>
<s>
In	O
Perl	B-Language
,	O
constructors	O
are	O
,	O
by	O
convention	O
,	O
named	O
"	O
new	O
"	O
and	O
have	O
to	O
do	O
a	O
fair	O
amount	O
of	O
object	O
creation	O
.	O
</s>
<s>
In	O
Moose	B-Language
object	I-Language
system	I-Language
for	O
Perl	B-Language
,	O
constructors	O
(	O
named	O
new	O
)	O
are	O
automatically	O
created	O
and	O
are	O
extended	O
by	O
specifying	O
a	O
BUILD	O
method	O
.	O
</s>
<s>
In	O
Visual	B-Language
Basic	I-Language
.NET	I-Language
,	O
the	O
constructor	O
is	O
called	O
"	O
New	O
"	O
.	O
</s>
<s>
In	O
Python	B-Language
,	O
the	O
constructor	O
is	O
split	O
over	O
two	O
methods	O
,	O
"	O
__new__	O
"	O
and	O
"	O
__init__	O
"	O
.	O
</s>
<s>
Object	B-Language
Pascal	I-Language
constructors	O
are	O
signified	O
by	O
the	O
keyword	O
"	O
constructor	O
"	O
and	O
can	O
have	O
user-defined	O
names	O
(	O
but	O
are	O
mostly	O
called	O
"	O
Create	O
"	O
)	O
.	O
</s>
<s>
In	O
Objective-C	B-Language
,	O
the	O
constructor	O
method	O
is	O
split	O
across	O
two	O
methods	O
,	O
"	O
alloc	O
"	O
and	O
"	O
init	O
"	O
with	O
the	O
alloc	O
method	O
setting	O
aside	O
(	O
allocating	O
)	O
memory	O
for	O
an	O
instance	O
of	O
the	O
class	O
,	O
and	O
the	O
init	O
method	O
handling	O
the	O
bulk	O
of	O
initializing	O
the	O
instance	O
.	O
</s>
<s>
"	O
heap	B-Application
"	O
.	O
</s>
<s>
are	O
created	O
in	O
a	O
sequential	O
structure	O
called	O
the	O
"	O
stack	B-Application
"	O
.	O
</s>
<s>
VB	B-Language
.NET	I-Language
and	O
C#	B-Application
also	O
allow	O
the	O
use	O
of	O
the	O
new	O
operator	O
to	O
create	O
value	O
type	O
objects	O
,	O
but	O
these	O
value	O
type	O
objects	O
are	O
created	O
on	O
the	O
stack	B-Application
regardless	O
of	O
whether	O
the	O
operator	O
is	O
used	O
or	O
not	O
.	O
</s>
<s>
In	O
C++	B-Language
,	O
objects	O
are	O
created	O
on	O
the	O
stack	B-Application
when	O
the	O
constructor	O
is	O
invoked	O
without	O
the	O
new	O
operator	O
,	O
and	O
created	O
on	O
the	O
heap	B-Application
when	O
the	O
constructor	O
is	O
invoked	O
with	O
the	O
new	O
operator	O
.	O
</s>
<s>
Stack	B-Application
objects	O
are	O
deleted	O
implicitly	O
when	O
they	O
go	O
out	O
of	O
scope	O
,	O
while	O
heap	B-Application
objects	O
must	O
be	O
deleted	O
implicitly	O
by	O
a	O
destructor	B-Language
or	O
explicitly	O
by	O
using	O
the	O
delete	O
operator	O
.	O
</s>
<s>
In	O
C++	B-Language
,	O
the	O
name	O
of	O
the	O
constructor	O
is	O
the	O
name	O
of	O
the	O
class	O
.	O
</s>
<s>
It	O
can	O
have	O
parameters	O
like	O
any	O
member	B-Language
function	I-Language
.	O
</s>
<s>
The	O
initializer	O
list	O
is	O
not	O
required	O
,	O
but	O
offers	O
the	O
opportunity	O
to	O
provide	O
values	O
for	O
data	B-Application
members	I-Application
and	O
avoid	O
separate	O
assignment	O
statements	O
.	O
</s>
<s>
The	O
initializer	O
list	O
is	O
required	O
if	O
you	O
have	O
const	O
or	O
reference	O
type	O
data	B-Application
members	I-Application
,	O
or	O
members	O
that	O
do	O
not	O
have	O
parameterless	O
constructor	O
logic	O
.	O
</s>
<s>
Assignments	O
occur	O
according	O
to	O
the	O
order	O
in	O
which	O
data	B-Application
members	I-Application
are	O
declared	O
(	O
even	O
if	O
the	O
order	O
in	O
the	O
initializer	O
list	O
is	O
different	O
)	O
.	O
</s>
<s>
C++	B-Language
allows	O
more	O
than	O
one	O
constructor	O
.	O
</s>
<s>
The	O
constructor	O
of	O
a	O
base	B-Application
class	I-Application
(	O
or	O
base	O
classes	O
)	O
can	O
also	O
be	O
called	O
by	O
a	O
derived	O
class	O
.	O
</s>
<s>
Constructor	O
functions	O
are	O
not	O
inherited	B-Language
and	O
their	O
addresses	O
cannot	O
be	O
referenced	O
.	O
</s>
<s>
If	O
it	O
is	O
not	O
provided	O
explicitly	O
,	O
the	O
compiler	O
uses	O
the	O
copy	O
constructor	O
for	O
each	O
member	B-Application
variable	I-Application
or	O
simply	O
copies	O
values	O
in	O
case	O
of	O
primitive	O
types	O
.	O
</s>
<s>
C++	B-Language
implicitly	O
generates	O
a	O
default	O
copy	O
constructor	O
which	O
will	O
call	O
the	O
copy	O
constructors	O
for	O
all	O
base	O
classes	O
and	O
all	O
member	B-Application
variables	I-Application
unless	O
the	O
programmer	O
provides	O
one	O
,	O
explicitly	O
deletes	O
the	O
copy	O
constructor	O
(	O
to	O
prevent	O
cloning	O
)	O
or	O
one	O
of	O
the	O
base	O
classes	O
or	O
member	B-Application
variables	I-Application
copy	O
constructor	O
is	O
deleted	O
or	O
not	O
accessible	O
(	O
private	O
)	O
.	O
</s>
<s>
reference	B-General_Concept
counting	I-General_Concept
,	O
deep	O
copy	O
of	O
pointers	O
)	O
also	O
require	O
customizing	O
the	O
destructor	B-Language
and	O
the	O
copy	O
assignment	O
operator	O
.	O
</s>
<s>
Example	O
C#	B-Application
constructor	O
:	O
</s>
<s>
In	O
C#	B-Application
,	O
a	O
static	O
constructor	O
is	O
a	O
static	O
data	O
initializer	O
.	O
</s>
<s>
Static	O
constructors	O
are	O
thread	B-Operating_System
safe	I-Operating_System
and	O
implement	O
a	O
singleton	O
pattern	O
.	O
</s>
<s>
When	O
used	O
in	O
a	O
generic	B-Language
programming	I-Language
class	O
,	O
static	O
constructors	O
are	O
called	O
at	O
every	O
new	O
generic	O
instantiation	O
one	O
per	O
type	O
.	O
</s>
<s>
CFML	B-Language
uses	O
a	O
method	O
named	O
'	O
init	O
 '	O
as	O
a	O
constructor	O
method	O
.	O
</s>
<s>
Since	O
ColdFusion	O
10	O
,	O
CFML	B-Language
has	O
also	O
supported	O
specifying	O
the	O
name	O
of	O
the	O
constructor	O
method	O
:	O
</s>
<s>
In	O
Eiffel	B-Language
,	O
the	O
routines	O
which	O
initialize	O
new	O
objects	O
are	O
called	O
creation	O
procedures	O
.	O
</s>
<s>
Creation	O
procedures	O
must	O
leave	O
the	O
newly	O
initialized	O
object	O
in	O
a	O
state	O
that	O
satisfies	O
the	O
class	B-Application
invariant	I-Application
.	O
</s>
<s>
In	O
this	O
case	O
the	O
list	O
includes	O
default_create	O
,	O
a	O
procedure	O
with	O
an	O
empty	O
implementation	O
inherited	B-Language
from	O
class	O
ANY	O
,	O
and	O
the	O
make	O
procedure	O
coded	O
within	O
the	O
class	O
.	O
</s>
<s>
Because	O
no	O
creation	O
procedure	O
is	O
specified	O
,	O
the	O
procedure	O
default_create	O
inherited	B-Language
from	O
class	O
ANY	O
is	O
used	O
.	O
</s>
<s>
In	O
F#	B-Operating_System
,	O
a	O
constructor	O
can	O
include	O
any	O
let	O
or	O
do	O
statements	O
defined	O
in	O
a	O
class	O
.	O
</s>
<s>
In	O
Java	B-Language
,	O
constructors	O
differ	O
from	O
other	O
methods	O
in	O
that	O
:	O
</s>
<s>
Java	B-Language
constructors	O
perform	O
the	O
following	O
tasks	O
in	O
the	O
following	O
order	O
:	O
</s>
<s>
Initialize	O
member	B-Application
variables	I-Application
to	O
the	O
specified	O
values	O
.	O
</s>
<s>
Java	B-Language
permit	O
users	O
to	O
call	O
one	O
constructor	O
in	O
another	O
constructor	O
using	O
this( )	O
keyword	O
.	O
</s>
<s>
Java	B-Language
provides	O
access	O
to	O
the	O
superclass	O
's	O
constructor	O
through	O
the	O
super	O
keyword	O
.	O
</s>
<s>
As	O
of	O
ES6	O
,	O
JavaScript	B-Language
has	O
direct	O
constructors	O
like	O
many	O
other	O
programming	O
languages	O
.	O
</s>
<s>
In	O
Object	B-Language
Pascal	I-Language
,	O
the	O
constructor	O
is	O
similar	O
to	O
a	O
factory	B-Language
method	I-Language
.	O
</s>
<s>
In	O
OCaml	B-Language
,	O
there	O
is	O
one	O
constructor	O
.	O
</s>
<s>
In	O
PHP	B-Application
version	O
5	O
and	O
above	O
,	O
the	O
constructor	O
is	O
a	O
method	O
named	O
__construct( )	O
(	O
notice	O
that	O
it	O
's	O
a	O
double	O
underscore	O
)	O
,	O
which	O
the	O
keyword	O
new	O
automatically	O
calls	O
after	O
creating	O
the	O
object	O
.	O
</s>
<s>
In	O
PHP	B-Application
,	O
a	O
class	O
is	O
only	O
allowed	O
to	O
declare	O
a	O
maximum	O
of	O
one	O
constructor	O
method	O
.	O
</s>
<s>
Static	B-Language
methods	I-Language
,	O
factory	O
classes	O
or	O
optional	O
constructor	O
arguments	O
are	O
some	O
ways	O
to	O
facilitate	O
multiple	O
ways	O
to	O
create	O
objects	O
of	O
a	O
PHP	B-Application
class	I-Application
.	O
</s>
<s>
In	O
Perl	B-Language
programming	I-Language
language	I-Language
version	O
5	O
,	O
by	O
default	O
,	O
constructors	O
are	O
factory	B-Language
methods	I-Language
,	O
that	O
is	O
,	O
methods	O
that	O
create	O
and	O
return	O
the	O
object	O
,	O
concretely	O
meaning	O
create	O
and	O
return	O
a	O
blessed	O
reference	O
.	O
</s>
<s>
With	O
the	O
Moose	B-Language
object	I-Language
system	I-Language
for	O
Perl	B-Language
,	O
most	O
of	O
this	O
boilerplate	O
can	O
be	O
left	O
out	O
,	O
a	O
default	O
new	O
is	O
created	O
,	O
attributes	O
can	O
be	O
specified	O
,	O
as	O
well	O
as	O
whether	O
they	O
can	O
be	O
set	O
,	O
reset	O
,	O
or	O
are	O
required	O
.	O
</s>
<s>
In	O
addition	O
,	O
any	O
extra	O
constructor	O
functionality	O
can	O
be	O
included	O
in	O
a	O
BUILD	O
method	O
which	O
the	O
Moose	B-Language
generated	O
constructor	O
will	O
call	O
,	O
after	O
it	O
has	O
checked	O
the	O
arguments	O
.	O
</s>
<s>
In	O
Python	B-Language
,	O
constructors	O
are	O
defined	O
by	O
one	O
or	O
both	O
of	O
__new__	O
and	O
__init__	O
methods	O
.	O
</s>
<s>
If	O
a	O
constructor	O
method	O
is	O
not	O
defined	O
in	O
the	O
class	O
,	O
the	O
next	O
one	O
found	O
in	O
the	O
class	O
's	O
Method	B-Application
Resolution	I-Application
Order	I-Application
will	O
be	O
called	O
.	O
</s>
<s>
(	O
The	O
most	O
common	O
exception	O
is	O
for	O
immutable	B-Application
objects	I-Application
.	O
)	O
</s>
<s>
Classes	O
normally	O
act	O
as	O
factories	B-Application
for	O
new	O
instances	O
of	O
themselves	O
,	O
that	O
is	O
,	O
a	O
class	O
is	O
a	O
callable	O
object	O
(	O
like	O
a	O
function	O
)	O
,	O
with	O
the	O
call	O
being	O
the	O
constructor	O
,	O
and	O
calling	O
the	O
class	O
returns	O
an	O
instance	O
of	O
that	O
class	O
.	O
</s>
<s>
With	O
Raku	B-Application
,	O
even	O
more	O
boilerplate	O
can	O
be	O
left	O
out	O
,	O
given	O
that	O
a	O
default	O
new	O
method	O
is	O
inherited	B-Language
,	O
attributes	O
can	O
be	O
specified	O
,	O
as	O
well	O
as	O
whether	O
they	O
can	O
be	O
set	O
,	O
reset	O
,	O
or	O
are	O
required	O
.	O
</s>
<s>
Alternatively	O
,	O
the	O
named	O
parameters	O
can	O
be	O
specified	O
using	O
the	O
colon-pair	O
syntax	O
in	O
Perl	B-Application
6	I-Application
:	O
</s>
<s>
In	O
Ruby	B-Language
,	O
constructors	O
are	O
created	O
by	O
defining	O
a	O
method	O
called	O
initialize	O
.	O
</s>
<s>
In	O
Visual	B-Language
Basic	I-Language
.NET	I-Language
,	O
constructors	O
use	O
a	O
method	O
declaration	O
with	O
the	O
name	O
"	O
New	O
"	O
.	O
</s>
