67,512
社区成员
发帖
与我相关
我的任务
分享
public interface Pen{
String getType();
}
public interface Paper{
String getSize();
}
public static class Pencil implements Pen{
@Override
public String getType() {
// TODO Auto-generated method stub
return "铅笔";
}
}
public static class FountainPen implements Pen{
@Override
public String getType() {
// TODO Auto-generated method stub
return "钢笔";
}
}
public static class A4paper implements Paper{
@Override
public String getSize() {
// TODO Auto-generated method stub
return "A4";
}
}
public static class B5paper implements Paper{
@Override
public String getSize() {
// TODO Auto-generated method stub
return "B5";
}
}
public static class Articlescrap{
private Pen pen;
private Paper paper;
public Pen getPen() {
return pen;
}
public void setPen(Pen pen) {
this.pen = pen;
}
public Paper getPaper() {
return paper;
}
public void setPaper(Paper paper) {
this.paper = paper;
}
public Articlescrap(Pen pen,Paper paper){
this.paper=paper;
this.pen=pen;
}
public void write() {
System.out.println("用"+pen.getType()+"配合"+paper.getSize()+"纸写小说");
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Articlescrap articlescrap1=new Articlescrap(new Pencil(), new A4paper());
articlescrap1.write();
Articlescrap articlescrap2=new Articlescrap(new FountainPen(), new B5paper());
articlescrap2.write();
}