分式打印机




package com.homeworlk;

public class User {
            public void pt(DotMatrixPrinter zhen) {
    zhen.print();
   }
            public void pt(IkpetPrinter penmo) {
    penmo.print();
   }
            public void pt(LaserPrinter jiguang) {
    jiguang.print();
   }
}

----------------------------------------------------------------------------------------------------------------------------------

package com.homeworlk;
/**
 * 针式打印机
 * @author 水瓶
 *
 */
public class DotMatrixPrinter extends Printer {
 public void print() {
  System.out.println("针式打印机工作!");
  
 }

}

package com.homeworlk;
/**
 * 喷墨打印机
 * @author 水瓶
 *
 */
public class IkpetPrinter extends Printer{
 public void print() {
  System.out.println("喷墨打印机正在工作!");
 }

}

package com.homeworlk;

public class LaserPrinter extends Printer{
 public void print() {
   System.out.println("激光打印机正在工作!");  
 }

}

----------------------------------------------------------------------------------------------------------------------------------

package com.homeworlk;

public class TestPrinter {
 /**
  * 测试DotMatrixPrinter类,IkpetPrinter类,LaserPrinter类
  * @author 水瓶
  *
  */
 public static void main(String[] args) {
  DotMatrixPrinter zhen = new DotMatrixPrinter();
  IkpetPrinter penmo = new IkpetPrinter();
  LaserPrinter jiguang = new LaserPrinter();
         User user = new User();
         user.pt(zhen);
 }

}

阅读更多

没有更多推荐了,返回首页