欢迎来到天天文库
浏览记录
ID:32592111
大小:59.39 KB
页数:8页
时间:2019-02-13
《07实验七包、接口和常用工具类》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、实验七包、接口和常用工具类程序清单7-1//Clock,javapackagepackone;publicclassClock{publicinthour;privateintminute;protectedintsecond;publicClock(inti,intj,intk){setAll(i,j,k);}voidsetAll(inti,intj,intk){hour=i;minute=j;second=k;}publicintgetHour(){returnhour;}publicintgetMinute(){returnminute;)publicintg
2、etSecond(){returnsecond;}}程序清单7-2//A.javapackagepackone;classA{publicstaticvoidmain(Stringf]args){Clockc=newClock(5,20J0);System.out.println(H从类A屮访问Clockhour=n+c.getHour());System.out.println(H从类A中访问Clockminute=,l+c.getMinute());System.out.printinC从类A中访问Clocksecond=H+c.getSecond());}}程
3、序清单7-3//B.javapackagepacktwo;importpackone.*;classB{publicstaticvoidmain(Stringnargs){Clockc=newClock(8,30,5);System.out.printing'从类B中访问Clockhour=,,+c.getHour());System.out.printin(”从类B中访问Clockminute=n+c.getMinute());System.out.println(!,从类B屮访问Clocksecond=H+c.getSecond());程序清单7-4//Inte
4、rfaceTest.javaimportjava.util.Scanner;interfaceSoundable{publicvoidincreaseVolume();publicvoiddecreaseVolume();publicvoidstopSound();publicvoidplaySound();}classRadioimplementsSoundable{publicvoidincreaseVolume(){System.out.printlnC'增大收音机音量”);}publicvoiddecreaseVolume(){System.out.prin
5、tlnC'减小收音机音量”);-3do(DdsseorK徹曲<换尼片・)upuyd.lno.uI3SAS-()punosA皂dPOA0二qnd(r^Hbs派=)uuukmo.ujesas-()punosdolsP-OA。二qnd-(=*协貝Hbw蹩・・)upuK・lno.uI3SAS一()QlunIQ/QSGQJOOPpo>。二qnd"(=*血男Hb+6、ndFfea坦府一氷.JUnuudMO.EESAS-()punosd2sPOA2一q^dFM血古K坦-KwJUUU-cdMo.luESAS一()QlunIO^QSEQJOWPOAOHqnd-u-qepunosscUUJYdlu一ueluz-eMsseo"(・feL轻罄男相学.)upu-cd.lno.HJ3SAS-()punosAJ2dP-O>。二qnd一(昊枷呈E^JUPU-cd.lno.lupsAS-()punosdo」sPOAo=qndprivateStringname;privateintage;publicvoidlisten(Soundables){s.p7、laySound();publicclassInterfaceTest{publicstaticvoidmain(S(ring[]args){inti;Peoplesportsman=newPeople();Scannerscanner=newScanner(System.in);Soundable[]soundDevice=newSoundable[3];〃往声音设备数组屮放入能发声的设备soundDevice[0]=newRadio();soundDevicefll=newWalkman();代码2〃创建手机对象并赋值给soundDevice⑵System.
6、ndFfea坦府一氷.JUnuudMO.EESAS-()punosd2sPOA2一q^dFM血古K坦-KwJUUU-cdMo.luESAS一()QlunIO^QSEQJOWPOAOHqnd-u-qepunosscUUJYdlu一ueluz-eMsseo"(・feL轻罄男相学.)upu-cd.lno.HJ3SAS-()punosAJ2dP-O>。二qnd一(昊枷呈E^JUPU-cd.lno.lupsAS-()punosdo」sPOAo=qndprivateStringname;privateintage;publicvoidlisten(Soundables){s.p
7、laySound();publicclassInterfaceTest{publicstaticvoidmain(S(ring[]args){inti;Peoplesportsman=newPeople();Scannerscanner=newScanner(System.in);Soundable[]soundDevice=newSoundable[3];〃往声音设备数组屮放入能发声的设备soundDevice[0]=newRadio();soundDevicefll=newWalkman();代码2〃创建手机对象并赋值给soundDevice⑵System.
此文档下载收益归作者所有