造函数,以上述日期格式数据为参数,创建date类型的对象。程序如下:packagedate;/****@authorAdministrator*/lassDate{intYYYY;intMM;intDD;publicDate(inty,intm,intd){?this.YYYY=y;this.MM=m;this.DD=d;}publicDate(){ this.YYYY=0;this.MM=0;?this.DD=0;}publicbooleanisValid(){ return(this.YYYY>0&&this.MM>0&&this.DD>0&&this.MM<13&&this.DD<32);?}?publicvoidshowYMD(){ System.out.println(this.YYYY+""+this.MM+""+this.DD);?}?publicvoidshowMDY(){ System.out.println(this.MM+""+this.DD+""+this.YYYY);?}?publicvoidshowDMY(){ System.out.println(this.DD+""+this.MM+""+this.YYYY);?}?publicstaticvoidmain(Stringargs[]){ Dateday1=newDate(); Dateday2=newDate(2003,12,1); if(day1.isValid()){?day1.showYMD();?day1.showMDY();day1.showDMY(); }if(day2.isValid()){day2.showYMD();?day2.showMDY();?day2.showDMY(); } }}运行结果如下:run:200312112120031122003成功构建(总时间:0秒)