首页 试题详情
问答题

阅读下列说明和java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图6-1所示的类图。 【java代码】 class invoice{ public void printInvoice( ){ System.out.println ( "This is the content of the invoice!"); } } class Decorator extends Invoice { protected Invoice ticket; public Decorator(lnvoice t){ ticket = t; } public void printInvoice( ){ if(ticket != null) (1) ; } } class HeadDecorator extends Decorator{ public HeadDecorator(lnvoice t){ super(t); } public void printInvoice ( ){ Systent.out.println( "This is the header of the invoice! "); (2) ; } } class FootDecorator extends Decorator { public FootDecorator(Invoice t){ super(t); } public void printlnvoice( ){ ( 3) ; Systent.out.println( "This is the footnote of the invoice! "); } } Class test { public static void main(String[] args){ Invoice t =new Invioce( ); Invoice ticket; ticket= (4) ; ticket.printInvoice( ); Systent.out.println(“------------------“); ticket= (5) ; ticket.printInvoice( ); } } 程序的输出结果为: This is the header of the invoice! This is the content of the invoice! This is the footnote of the invoice! ---------------------------- This is the header of the invoice! This is the footnote of the invoice!

正确答案:A (备注:此答案有误)

相似试题

  • 单选题

    下列代码的下划线处填入的方法名是:import java.applet.*;import java.awt.*;public class Hello extends Applet { public void _____(Graphics g){ g.drawString(How are you!, 10, 10); }}

    答案解析

  • 问答题

    阅读以下说明Java代码,填充程序中的空缺,解答填入答题纸的对应栏内。[说明]某应急交通控制系统(TraficControlSystem)在红灯时控制各类车辆(Vehicle)的通行,其类图如下图所示,在紧急状态下应急车辆在红灯时可通行,其余车辆按正常规则通行。下面的Java代码实现以上设计,请完善其中的空缺。[Java代码]abstract class Vehicle{public Vehicle(){ }abstract void run();};interface Emergency{ ______; ______;};class Car extends Vehicle{public Car(){ }void run(){ /*代码略*/ }};Class Truck extends Vehicle{public Truck(){ }void run() { /*代码略*/ }};class PoliceCar ______ {boolean isEmergency= false;public PoliceCar(){ }public PoliceCa

    答案解析

  • 问答题

    第五题 阅读以下说明Java代码,填补代码中的空缺,解答填入答题纸的对应栏内。【说明】以下Java代码实现一个超市简单销售系统中的部分功能,顾客选择图书等物件 (Item)加入购物车(ShoppingCart),到收银台(Cashier)对每个购物车中的物品统计其价格进行结账。设计如图5-1所示类图。问题:5.1 【Java代码】interface Item{ public void accept(Visitor visitor); public double getPrice();}class Book (1){ private double price; public Book(double price){(2);} public void accept(Visitor visitor){ //访问本元素 (3); } public double getPrice() { return price; }}//其它物品类略 interface Visitor { public voi

    答案解析

  • 单选题

    Java中,阅读下列文件定入的Java代码,共有( )处错误import java.io.*;public class TestIO {public static void main(String []args){ String str ="文件写入练习";FileWriter fw = null; //1try{fw = new FileWriter("c: mytext.txt"); //2fw.writerToEnd(str); //3}catch(IOException ex){ ex.printStackTrace();}}}

    答案解析

  • 问答题

    阅读下列说明java代码填入 (n) 处的字句写在答题纸的对应栏内。【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图6-1所示的类图。【java代码】class invoice{public void printInvoice( ){ System.out.println ( This is the content of the invoice!); }}class Decorator extends Invoice { protected Invoice ticket; public Decorator(lnvoice t){ ticket = t;} publicvoid printInvoice( ){ if(ticket != null) (1) ; } }class HeadDecorator extends Decorato

    答案解析

热门题库