Constructor
A constructor is a function that initializes a newly allocated object.
Related concepts: ClassObjectMethod
Closest Wikipedia entry: Constructor (object-oriented programming) — In class-based, object-oriented programming, a constructor (abbreviation: ctor) is a special type of function 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.
Misconceptions about Constructor18 documented Misconceptions
Check YourselfAllClassesHaveDefaultConstructor — Java
All classes automatically get a no-argument constructorCannotChainAttributeToObjectInstantiation — Python
Method calls, and attribute accesses in general, cannot be chained to a constructor invocation.CannotChainMemberToConstructor — Java
Method calls or field accesses cannot be chained to a constructor invocationConstructorAllocates — Java
The constructor allocates the objectConstructorParameterIsField — Java
Formal constructor parameters are equivalent to instance variablesConstructorReturnsObject — Java
Constructors need to return objectsConstructorWithoutNew — Java
One can write the constructor name, without new, to instantiate a classImmutableRequiresFinalParameters — Java
Immutable classes need final constructor/method parametersInitCreates — Python
__init__ must create a new objectInitReturnsObject — Python
__init__ needs to return an objectMustInitializeFieldInConstructor — Java
Constructors must assign values to all fieldsNoEmptyConstructor — Java
A constructor must do somethingNoEmptyInit — Python
__init__ must do somethingNoInsideMethodCallInConstructor — Java
It is foirbidden to call other methods on the same object while inside its constructorObjectLabeledWithConstructorSignature — Java
In stack and heap diagrams, an object on the heap is labeled like a stack frame of a constructor callObjectsMustBeNamed — Java
A variable is needed to instantiate an objectObjectsMustBeNamed — Python
A variable is needed to instantiate an objectThisInConstructorIsNull — Java
In a constructor, this is null