欢迎来到天天文库
浏览记录
ID:38746808
大小:164.00 KB
页数:15页
时间:2019-06-18
《作业6(接口题上机)含答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、习题1具有照像功的设备:手机Phone,数码照像机Camera,平板电脑Tabletpc请遵循照像功能Photographable实现其PublicvoidtakePhoto()方法提示分别是设计3种设备的类,分别实现其照像功能的接口packagecn.com;publicclassCameraextendsPhotographableimplementsTakePhoto{publicCamera(Stringname){super(name);System.out.println("---有参---"+name);}publicCamera(){}publicvoidtakePhoto(
2、){System.out.println(getName()+":像素很高");}@OverridepublicvoidtakePhotoint(){//TODOAuto-generatedmethodstubSystem.out.println(getName()+"有夜间模式,微距离模式等");}}packagecn.com;publicclassPhoneextendsPhotographableimplementsTakePhoto{publicPhone(Stringname){super(name);System.out.println("---有参---"+name);}pub
3、licPhone(){}publicvoidtakePhoto(){System.out.println(getName()+":像素低");}@OverridepublicvoidtakePhotoint(){//TODOAuto-generatedmethodstubSystem.out.println(getName()+"有傻瓜照相功能,还能打电话");}}packagecn.com;publicclassTabletPCextendsPhotographableimplementsTakePhoto{publicTabletPC(Stringname){super(name);Sy
4、stem.out.println("---有参---"+name);}publicTabletPC(){}publicvoidtakePhoto(){System.out.println(getName()+":像素还行");}@OverridepublicvoidtakePhotoint(){//TODOAuto-generatedmethodstubSystem.out.println(getName()+"屏幕大,看得爽,还能玩高清游戏");}}packagecn.com;publicabstractclassPhotographable{privateStringname;publi
5、cStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicPhotographable(Stringname){this.name=name;}publicPhotographable(){}publicabstractvoidtakePhoto();}packagecn.com;publicabstractinterfaceTakePhoto{publicvoidtakePhotoint();}packagecn.com.test;importcn.com.Camera;importcn
6、.com.Phone;importcn.com.Photographable;importcn.com.TabletPC;publicclassTestPhoto{/***@paramargs*/publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubPhotographablepho=newPhone("洛基亚");pho.takePhoto();if(phoinstanceofPhone){Phonep1=(Phone)pho;p1.takePhotoint();}System.out.println("*****
7、******************");Phoneph=newPhone("小米");ph.takePhoto();ph.takePhotoint();Cameraca=newCamera("索尼数码");ca.takePhoto();ca.takePhotoint();TabletPCta=newTabletPC("ipad");ta.takePhoto();ta.takePhotoint();}}习题2
此文档下载收益归作者所有