Constructor (object-oriented programming)

In class-based, object-oriented programming, a constructor (abbreviation: ctor) is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables.

Comment
enIn class-based, object-oriented programming, a constructor (abbreviation: ctor) is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables.
Has abstract
enIn class-based, object-oriented programming, a constructor (abbreviation: ctor) is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables. A constructor resembles an instance method, but it differs from a method in that it has no explicit return type, it is not implicitly inherited and it usually has different rules for scope modifiers. Constructors often have the same name as the declaring class. They have the task of initializing the object's data members and of establishing the invariant of the class, failing if the invariant is invalid. A properly written constructor leaves the resulting object in a valid state. Immutable objects must be initialized in a constructor. Most languages allow overloading the constructor in that there can be more than one constructor for a class, with differing parameters. Some languages take consideration of some special types of constructors. Constructors, which concretely use a single class to create objects and return a new instance of the class, are abstracted by factories, which also create objects but can do so in various ways, using multiple classes or different allocation schemes such as an object pool.
Hypernym
Type
Is primary topic of
Constructor (object-oriented programming)
Label
enConstructor (object-oriented programming)
Link from a Wikipage to another Wikipage
((constructor))
ActionScript
Allocation site
Base class
C++
C3 linearization
Category:Method (computer programming)
Category:Programming language comparisons
CFML
Class (computer science)
Class-based programming
Class invariant
Creational pattern
C Sharp (programming language)
Data member
Deep copy
Default constructor
Destructor (computer science)
Eiffel (programming language)
Factory (object-oriented programming)
Factory method
F Sharp (programming language)
Generic programming
Global constructor
Heap (data structure)
Immutable object
Inheritance (object-oriented programming)
Initialization (computing)
Initializer list
Java (programming language)
JavaScript
MATLAB
Member variable
Method (computer programming)
Method (computer science)
Method overloading
Moose perl
Move constructor (C++)
Named parameter
Object (computer science)
Object creation
Objective-C
Object-oriented programming
Object Pascal
Object pool
OCaml (programming language)
Parameter (computer programming)
Parameter (computer science)
Perl
PHP
Python (programming language)
Raku (programming language)
Reference counting
Resource acquisition is initialization
Return type
Return value optimization
Ruby (programming language)
Rule of three (C++ programming)
Singleton pattern
Stack (abstract data type)
Subroutine
Superclass (computer science)
Thread safe
Visual Basic .NET
SameAs
8N3h
Constructeur (programmation)
Constructor
Constructor (informática)
Constructor (object-oriented programming)
Construtor
Costruttore (informatica)
Hàm tạo (lập trình hướng đối tượng)
Konstruktor
Konstruktor
Konstruktor (programowanie obiektowe)
Konstruktor (računalništvo)
Konstruktoren und Destruktoren
Konstruktorius (Objektinis programavimas)
m.03rvkg
Q1049476
Деструктор
Конструктор (обектно ориентирано програмиране)
Конструктор (объектно-ориентированное программирование)
Конструктор (програмування)
בנאי (מדעי המחשב)
دالة البناء (برمجة كائنية التوجه)
سازنده (برنامه‌نویسی شیءگرا)
कंसट्रक्टर
கட்டுநர் (பொருள் நோக்கு நிரலாக்கம்)
コンストラクタ
构造器
생성자
SeeAlso
Copy constructor (C++)
Subject
Category:Method (computer programming)
Category:Programming language comparisons
WasDerivedFrom
Constructor (object-oriented programming)?oldid=1124101288&ns=0
WikiPageLength
34973
Wikipage page ID
939453
Wikipage revision ID
1124101288
WikiPageUsesTemplate
Template:Efn
Template:Notelist
Template:ProgLangCompare
Template:Reflist
Template:See also
Template:Short description