Content deleted Content added
No edit summary Tags: Reverted Mobile edit Mobile web edit |
DreamRimmer (talk | contribs) Reverting edit(s) by 77.137.77.211 (talk) to rev. 1157671443 by Cngzz1: (RW 16.1) |
||
Line 2:
{{ProgLangCompare}}
A constructor resembles an [[method (computer science)|instance method]], but it differs from a method in that it has no explicit [[return type]], it is not implicitly [[inheritance (object-oriented programming)|inherited]] and it usually has different rules for scope modifiers. Constructors often have the same name as the declaring [[class (computer science)|class]]. They have the task of [[initialization (computing)|initializing]] the object's [[data member]]s and of establishing the [[Class invariant|invariant of the class]], failing if the invariant is invalid. A properly written constructor leaves the resulting [[object (computer science)|object]] in a ''valid'' state. [[Immutable object]]s must be initialized in a constructor.
|