This section contains 509 words (approx. 2 pages at 300 words per page) |
A constructor is a special function belonging to a class that builds objects of that class from nothing. Its chief purpose is to take an arbitrary collection of bits and bytes in the computer's memory and turn them into a valid object, complete with initialized internal data members and pointers to the code that represents the functions the object owns. A constructor is called automatically at the time an object is created.
The constructor method is typically named after the class for which it builds objects; thus the constructor of a class called "lunchBox" will also be called "lunchBox()."
In Java and C++, probably the two most common object-oriented programming languages, a class must have at least one constructor, but it can have many more. This is because Java and C++ both support "function overloading," which means the compiler can distinguish between functions that have the same name...
This section contains 509 words (approx. 2 pages at 300 words per page) |