Java Reference
In-Depth Information
MyClass( )
is overloaded four ways, each constructing an object differently. The proper
constructor is called based upon the parameters specified when
new
is executed. By over-
loading a class' constructor, you give the user of your class flexibility in the way objects
are constructed.
One of the most common reasons that constructors are overloaded is to allow one object
to initialize another. For example, consider this program that uses the
Summation
class to
compute the summation of an integer value: