//定义一个抽象基类Shape,其中包含area方法abstractclassShape{publicabstractdoublearea();}//定义Cirele并且继承Shape类,实现area方法classCircleextendsShape{privatedoubler;publicCircle(doubler){this.r=r;}publicdoublearea(){returnMath.PI*r*r;}}//定义Rectangle并且继承Shape类,实现area方法,并且对其进行重载classRectangleextendsShape{privatedoubler;privatedoublelength;publicRectangle(doubler,doublelength){this.r=r;this.length=length;}publicdoublearea(){doubletemp;temp=2*Math.PI*r*length;returntemp+2*Math.PI*r*r;}publicdoublearea(doubler,doublelength){doubletemp;temp=2*Math.PI*r*length;returntemp+2*Math.PI*r*r;}}//定义MyTest作为测试类publicclassMyTest{publicstaticvoidmain(String[]args){Circled=newCircle(2);Rectangles=newRectangle(2,2);System.out.println(d.area());System.out.println(s.area());System.out.println(s.area(3,3));}}importjava.util.*;classMydate{privateCalendardate=Calendar.getInstance();publicvoidsetTime(inthour,intminute,intsecond){Datetemp=newDate();Temp.sethous(hour);Temp.setminutes(minute);Temp.setseconds(second);date.setTime(temp);}publicvoidsetDate(intyear,intmonth,intday){date.set(year,month-1,day);}publicStringgetNowDate(){returndate.get(Calendar.YEAR)+年+(date.get(Calendar.MONTH)+1)+月+date.get(Calendar.DAY_OF_MONTH)+日;}publicStringgetNowTime(){returndate.get(Calendar.HOUR)+:+date.get(Calendar.MINUTE)+:+date.get(Calendar.SECOND);}}publicclassTest{publicstaticvoidmain(String[]args){Mydatemy=newMydate();System.out.println(my.getNowDate());System.out.println(my.getNowTime());my.setDate(2012,9,9);my.setTime(1,12,12);System.out.println(my.getNowDate());System.out.println(my.getNowTime());}}