Object-Oriented Notes
Approach
Class Scope
Overloaded Constructors
A method's signature refers to the number, types and order of the arguments in the parameter list.
Methods of a class can be overloaded, but only by other methods of the same class.
To overload a method of a class, simply provide an additional method definition with the same name as the original method, but with a different parameter list.
The appropriate constructor is determined by checking the method signature specified in the constructor call with the signature specified in each method definition.
If a redefinition of a method has a different signature than the original method, it is method overloading .
Constructors can be overloaded to initialize one, some, or all of an object's instance variables.
The next example overloads the
New constructor method to provide a convenient variety of ways to initialize clsTime objects.
|
|
The appropriate constructor is determined by checking the number, types and order of the arguments specified in the constructor call with the number, types and order of the parameters specified in each method definition.
The matching constructor is called automatically.