SHAOXIAOJ正在加载中...

2245: 多态-打印机程序

金币值:2 定数:6 时间限制:1.000 s 内存限制:128 M
正确:0 提交:0 正确率:0.00% 命题人:
点赞量:0 收藏量:0 题目类型:程序 知识点: Java

题目描述

使用Java多态思想编程实现"打印机”功能
编写黑白打印机、彩色打印机打印输出多态程序。
(1)编写一个Printer类,包含print()方法;编写黑白打印机BlackWhitePrinter和彩色打印机ColorPrinter类继承自Printer类,并重写print ()方法;
(2)编写一个类,提供对两类打印机员进行查看doPrint()方法。
写出打印机工作多态程序,并写出测试用例。
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		String brand;
		Scanner in = new Scanner(System.in);
		brand = in.nextLine();
		doPrint(new BlackWhitePrinter(brand));
		doPrint(new ColorPrinter(brand));
	}
	public static void doPrint(Printer e){
		e.print();
	}
}
/* 以下为你的代码 */

输入格式

输入1行:品牌

输出格式

见样例

输入样例    复制

HP

输出样例    复制

HP打印黑白信息
HP打印彩色信息