Constructor (object-oriented programming): Difference between revisions

Content deleted Content added
No edit summary
STBot (talk | contribs)
m clean up - bother me at my talk if I mess up using AWB
Line 1:
In [[object-oriented programming]], a '''constructor''' (sometimes shorted to '''ctor''') in a class is a special [[method (computer science)|method]] (function) called when an object is declared and never has a return type. Constructors are special [[method (computer science)|instance methods]] that are called automatically upon the creation of an [[object (computer science)|object]] (instance of a class). They are often distinguished by having the same name as the [[class (computer science)|class]] of the object they're associated with. Its main purpose is to pre-define the object's [[data member|data members]]s and to establish the [[invariant (computer science)|invariant]] of the class, failing if the invariant isn't valid. A properly written constructor will leave the [[object (computer science)|object]] in a 'valid' state.
 
=== [[Java programming language|Java]] ===
Line 83:
* [[Bjarne Stroustrup]]: ''The C++ Programming Language'', Addison-Wesley, ISBN 0-201-70073-5
 
[[categoryCategory:Programming constructs]]
 
[[de:Kopierkonstruktor]]