O'Reilly logo

Visual C#® 2012: How to Program, Fifth Edition by Harvey Deitel, Paul Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

10.5. Time Class Case Study: Overloaded Constructors

Next, we demonstrate a class with several overloaded constructors that enable objects of that class to be conveniently initialized in different ways. To overload constructors, simply provide multiple constructor declarations with different signatures.

Class Time2 with Overloaded Constructors

By default, instance variables hour, minute and second of class Time1 (Fig. 10.1) are initialized to their default values of 0—midnight in universal time. Class Time1 doesn’t enable the class’s clients to initialize the time with specific nonzero values. Class Time2 (Fig. 10.5) contains overloaded constructors. In this app, one constructor invokes the other constructor, which in turn calls SetTime to set ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required