9.5. Time Class Case Study: Overloaded Constructors

Like methods, constructors of a class can be overloaded. To do so, provide a separate method declaration with the same name (New) for each version of the method but different numbers, types and/or orders of parameters.

Class Time with Overloaded Constructors

The Time constructor in Fig. 9.1 initialized hourValue to 12 and minuteValue and secondValue to 0 (i.e., noon) with a call to the class’s SetTime method. Recall that the declaration in line 4 of Fig. 9.2 supplied no arguments to the Time class constructor. Suppose you would like to create Time objects with any legitimate hour, minute and/or second values. Class Time of Fig. 9.3 includes five overloaded constructors to provide several ways ...

Get Visual Basic 2005 for Programmers: Deitel Developer Series, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.