Java第四周常用类与集合框架之接口+抽象类9-9
来源:互联网 发布:sopcast2016地址源码 编辑:程序博客网 时间:2024/06/05 23:53
1、定义接口:package test9_9photo;public interface InterfaceTest { String action="照相"; public void picture(String stype);}2、定义抽象类:package test9_9photo;public abstract class InterfaceTest_phone { String phonestyle="手机"; public abstract void phoneofphoto(String stype); public String toString(){ return "这是:"+phonestyle; }}3、定义抽象类的子类手机的子类拍照类继承抽象类和接口:package test9_9photo;public class InterfaceTest_picturephone extends InterfaceTest_phone implements InterfaceTest { public String picture="高像素小清新拍照手机"; public void takepicturetest() { System.out.println("%%%%%%%%%%%%%%%%%"); System.out.println(" 类的InterfaceTest_picturephone的takepicture()方法中"); System.out.println("&&&&&&&&&&……………………&&&&&&&"); picture(action+"\n"); } public void picture(String stype) { System.out.println(" 这是:"+stype); phoneofphoto(phonestyle+"子类的拍照手机!"); } public void phoneofphoto(String stype) { System.out.println("\n"+stype); this.toString(); }}4、子类手机的子类拍照类的测试类写上main()方法,运行起来:package test9_9photo;public class InterfaceTest_picturephonemain { public static void main(String[] args){ InterfaceTest_picturephone picturephone=new InterfaceTest_picturephone(); picturephone.takepicturetest(); picturephone.picture(picturephone.picture); picturephone.picture(picturephone.phonestyle); picturephone.phoneofphoto(picturephone.picture); }}运算结果呢:%%%%%%%%%%%%%%%%% 类的InterfaceTest_picturephone的takepicture()方法中&&&&&&&&&&……………………&&&&&&& 这是:照相手机子类的拍照手机! 这是:高像素小清新拍照手机手机子类的拍照手机! 这是:手机手机子类的拍照手机!高像素小清新拍照手机5、定义抽象类的另一个子类普通手机只继承抽象类手机类:package test9_9photo;public class InterfaceTest_usualphone extends InterfaceTest_phone{ String typeofphone="普通手机!"; public void phoneofphoto(String stype) { System.out.println("这是:"+stype+"\n"); }}6、普通手机的测试类,然后写main()方法,进行具体实现调用测试功能:package test9_9photo;public class InterfaceTest_usualphonemain { public static void main(String[] args) { InterfaceTest_usualphone usual=new InterfaceTest_usualphone(); usual.phoneofphoto(usual.typeofphone); }}7、测试运行结果:这是:普通手机!
0 0
- Java第四周常用类与集合框架之接口+抽象类9-9
- Java第四周常用类与集合框架上机实验一接口+抽象类
- Java第四周常用类与集合框架上机实验二学会Math类常用方法使用
- Java第四周常用类与集合框架上机实验三学会String类常用方法使用
- Java第四周常用类与集合框架上机实验四学会包装类常用方法使用
- Java第四周常用类与集合框架上机实验五学会Date类常用方法使用
- JAVA学习之:抽象类与接口
- Java学习之---抽象类与接口
- Java基础之抽象类与接口
- java温故而知新之接口与抽象类
- java学习之抽象类与接口
- Java初学者之接口与抽象类
- JAVA之接口与抽象类详解
- Java基础之抽象类与接口
- Java常用集合类框架的基本接口
- Java Head First 第8章 接口与抽象类
- 9、抽象类与接口
- 集合接口与抽象类 collection接口 Iterator接口
- Android技能学习
- Eclipse使用小技巧——备忘
- js解决onkeydown长按按键卡顿一下
- MJExtension字典和模型之间相互转换的轻量级框架的使用实例
- New package not yet registered with the system. Waiting 3 seconds before next attempt
- Java第四周常用类与集合框架之接口+抽象类9-9
- linux 下面清除历史纪录的方法
- Python 代码风格和PEP8
- 仿淘宝,自定义ViewGroup实现自动换行布局
- vim配置YCM
- Android的Style的使用和用处
- 第一次只出现一次的字符
- USACO 1.1 Friday the Thirteenth
- Netsh命令详解