public class Date { private int hours; // 0-23 private int minutes; // 0-59 private int seconds; // 0-59 // constructors are overloaded below public Date() {setHours(0); setMinutes(0); setSeconds(0);} // since other constructors are defined, zero-argument constructor no longer available // by default and hence must be defined if it is to be invoked public Date(int hours) { setHours(hours); // parameter hours is repassed to setHours method setMinutes(0); setSeconds(0);}// constructor has same name as class and doesn't have a return type // because signature of constructor below is identical to one above, it is illegal // in some cases, the parameters will naturally be of different types so one can distinguish // one method from another // public Date(int minutes) { setMinutes(minutes); // parameter hours is repassed to setHours method // setHours(0); // setMinutes(minutes); //setSeconds(0);}// constructor has same name as class and doesn't have a return type public Date(int hours, int minutes) { setHours(hours);setMinutes(minutes);setSeconds(0);} public Date(int hours, int minutes, int seconds) { setHours(hours);setMinutes(minutes); setSeconds(seconds);} public void setHours (int hours) { if (hours<0 || hours>23) this.hours = 0; // this keyword used to refer to calling object else this.hours = hours;} // this keyword required when instance variable and parameter // (or any local variable) have the same name public void setMinutes (int sminutes) { minutes = (sminutes<0 || sminutes>59)?0:sminutes; // equivalent to if test above } public void setSeconds (int sseconds) { seconds = (sseconds<0 || sseconds>59)?0:sseconds; } public int getHours() {return hours;} public int getMinutes() {return minutes;} public int getSeconds() {return seconds;} public String toString() { // no parameters since all necessary info in object return hours + ":" + minutes + ":" + seconds; // default toString method doesn't // return anything familiar so we want to output in hours:minutes:seconds format } }