- 客户的第一次需求:开发一个打印机控制程序
- 客户的第二次需求:两个打印机的选择程序
classPrinter{
void open(){
System.out.println("open");
}
void close(){
System.out.println("close");
}
void print(String s){
System.out.println("print-->"+ s);
}
}
classHPPrinter extends Printer{
}
classCanonPrinter extends Printer{
void close(){
this.clean();
super.close();
}
void clean(){
System.out.println("clean");
}
}
classTest{
publicstaticvoid main(String args []){
int flag =1;
if(flag ==0){
HPPrinter hpPrinter =newHPPrinter();
hpPrinter.open();
hpPrinter.print("abc");
hpPrinter.close();
}
elseif(flag ==1){
CanonPrinter canonPrinter =newCanonPrinter();
canonPrinter.open();
canonPrinter.print("123");
canonPrinter.close();
}
}
}
时间: 2024-11-07 07:51:10