Chapter 8 Object-Based Programming 299 13 // Time3 (Virtual web hosting)
Chapter 8 Object-Based Programming 299 13 // Time3 constructor initializes instance variables to 14 // zero to set default time to midnight 15 public Time3() 16 { 17 SetTime( 0, 0, 0 ); 18 } 19 20 // Time3 constructor: hour supplied, minute and second 21 // defaulted to 0 22 public Time3( int hour ) 23 { 24 SetTime( hour, 0, 0 ); 25 } 26 27 // Time3 constructor: hour and minute supplied, second 28 // defaulted to 0 29 public Time3( int hour, int minute ) 30 { 31 SetTime( hour, minute, 0 ); 32 } 33 34 // Time3 constructor: hour, minute and second supplied 35 public Time3( int hour, int minute, int second ) 36 { 37 SetTime( hour, minute, second ); 38 } 39 40 // Time3 constructor: initialize using another Time3 object 41 public Time3( Time3 time ) 42 { 43 SetTime( time.Hour, time.Minute, time.Second ); 44 } 45 46 // Set new time value in 24-hour format. Perform validity 47 // checks on the data. Set invalid values to zero. 48 public void SetTime( 49 int hourValue, int minuteValue, int secondValue ) 50 { 51 Hour = hourValue; // invoke Hour property set 52 Minute = minuteValue; // invoke Minute property set 53 Second = secondValue; // invoke Second property set 54 } 55 56 // property Hour 57 public int Hour 58 { 59 get 60 { 61 return hour; 62 } 63 Fig. 8.6 Fig. 8.Fig.Fi 8.6g. 8.66Properties provide controlled access to an object s data. (Part 2 of 3.) Fig. 8.
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.