首先定义墨盒跟纸张的接口
public interface Cartridge {
public String color();
}
public interface Size {
public String paper();
}
然后对接口进行实例化
public class Test implements Size {
@Override
public String paper() {
// TODO Auto-generated method stub
return "A4纸张";
}
public class Test1 implements Size{
@Override
public String paper() {
// TODO Auto-generated method stub
return "B5纸张";
}
public class Test2 implements Cartridge {
@Override
public String color() {
// TODO Auto-generated method stub
return "彩色墨盒";
}
public class Printer {
public static void print(Size Test,Size Test1,Cartridge Test2){
System.out.println("使用"+Test2.color()+Test1.paper()+"打印");
}
然后进行测试
public class Ceshi {
public static void main(String[] args) {
Printer.print(new Test(),new Test1(),new Test2());
}
}