package com.java_study.chapter17.interface1;/** * 墨盒类 * @author Administrator * */public interface InkBox {public String getInkBox();}package com.java_study.chapter17.interface1Impl;import com.java_study.chapter17.interface1.InkBox;/** * 黑白墨盒 * @author Administrator * */public class BInkBox implements InkBox{public String getInkBox(){return "黑白";}}package com.java_study.chapter17.interface1Impl;import com.java_study.chapter17.interface1.InkBox;/** * 彩色墨盒 * @author Administrator * */public class CInkBox implements InkBox{public String getInkBox(){return "彩色";}}*****************************************************************package com.java_study.chapter17.interface1;/** * 纸张接口 * @author Administrator * */public interface Paper {public String getPaper();}package com.java_study.chapter17.interface1Impl;import com.java_study.chapter17.interface1.Paper;/** * A4纸张类 * @author Administrator * */public class PaperA4 implements Paper{public String getPaper(){return "A4";}}package com.java_study.chapter17.interface1Impl;import com.java_study.chapter17.interface1.Paper;/** * B5纸张类 * @author Administrator * */public class PaperB5 implements Paper{public String getPaper(){return "B5";}}***************************************************************package com.java_study.chapter17.interface1Impl;import com.java_study.chapter17.interface1.InkBox;import com.java_study.chapter17.interface1.Paper;/** * 测试类 * @author Administrator * */public class Test_interface1 {public static void main(String[] args) {Paper paper;InkBox inkbox; paper=new PaperA4();inkbox=new CInkBox();//A4大小的彩色纸张System.out.println("我的打印机可以打印"+paper.getPaper()+"大小的"+inkbox.getInkBox()+"的纸张");//B5大小的黑白纸张paper=new PaperB5();inkbox=new BInkBox();System.out.println("我的打印机可以打印"+paper.getPaper()+"大小的"+inkbox.getInkBox()+"的纸张");}}
Java基础之接口的简单实现
最新推荐文章于 2022-11-23 17:00:18 发布