首页
登录
从业资格
某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构
某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构
最全题库
2022-08-02
113
问题
某发票(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!
选项
答案
解析
(1)ticket.printInvoice()
(2)super.printInvoice()
(3)super.printInvoice()
(4)new HeadDecorator(new FootDecorator(t))
(5)new HeadDecorator(new FootDecorator(null))
本题考查的是面向对象程序设计和设计模式。本题涉及的设计模式是装饰模式。
装饰模式(Decorator):动态地给一个对象添加一些额外的职责。它提供了用子类扩展功能的一个灵活的替代,比派生一个子类更加灵活。
对于程序填空可以参照代码上下文、题干说明和设计模式综合考虑。
对于第(1)空,是对printInvoice方法的具体调用,在Decorator是装饰类,继承了Invoice发票类。此处需要填写的是printInvoice方法的方法体,根据Decorator类的上下文,已定义ticket对象,所以此处调用printInvoice方法的是ticket,第(1)空填写ticket.printInvoice()。
对于第(2)(3)空,根据类图可知,分别是HeadDecorator抬头类、FootDecorator脚注类调用printInvoice方法的方法体,由于在这两个类中并没有定义属性,只有借助其超类的构造函数,所以这两个地方调用printInvoice方法的是它们的超类,即(2)(3)填写的是super.printInvoice()。
对于第(4)(5)空,考查的是对装饰模式的调用,都是main函数中实例化的过程,根据输出结果可以看到,第(4)空实例化ticket对象,可以输出抬头、内容、脚注3个部分,因此需要调用三者的printInvoice()方法,前面已经实例化了一个Invoice对象t,可以利用t给子类实例化,因此第(4)空填写new HeadDecorator(new FootDecorator(t));而第(5)空没有输出具体内容,只有抬头和脚注部分,可以看到这里的Invoice对象应该是空,所以第(5)空填写new HeadDecorator(new FootDecorator(null))。
转载请注明原文地址:http://tihaiku.com/congyezige/2409649.html
本试题收录于:
中级 软件设计师题库软件水平考试初中高级分类
中级 软件设计师
软件水平考试初中高级
相关试题推荐
天津市某银行信息系统的数据库部分关系模式如下所示: 客户(客户号,姓名,性别,
某超市销售系统的部分关系模式如下:商品表:Commodity(Ccode,C
数据库应用系统在运行过程中,发现随着数据量的不断增加,有部分查询业务和数据更新业
某图书馆的管理系统部分需求和设计结果描述如下:图书馆的主要业务包括以下几项:
某工厂的信息管理数据库的部分关系模式如下所示:职工(职工号,姓名,年龄,月工资,
某健身俱乐部要开发一个信息管理系统,该信息系统的部分关系模式如下:员工(员工身份
某汽车租赁公司建立汽车租赁管理系统,其数据库的部分关系模式如下:用户:USERS
现有一部分U/C矩阵如下表所示,则下列描述不正确的是()。A.成品库存信息是在
某公司要对其投放的自动售货机建立商品管理系统,其数据库的部分关系模式如下:售货机
某大型集团公司的数据库的部分关系模式如下:员工表:EMP(Eno,Ename,A
随机试题
IntheartoftheMiddleAges,weneverencounterthepersonalityoftheart
Whentheyoungstersheardthenews,they______.[br]Thephrase"aregoingtoa
[originaltext]Everydayconversationisessentialtoseveralaspectsoflife
我国台湾地区关于公示原则的法律效果采取的是( )。A.登记成立主义 B.登记
有一位先哲说过:“一个人的性格就是他的命运。”说明人格具有()。A.稳定性 B
完全性右束支阻滞的特征性心电图改变是 A.QRS波群时限12sB.V1或
公文的份号,即份数序号,一般由()位3号阿拉伯数字组成。A.4 B.5 C.
治疗年轻恒牙的操作中,不妥当的是A.考虑年轻恒牙的形态、组织结构和生理特点 B
根据税收法律制度的规定,下列各项中,适用超率累进税率的是()。A.印花税 B
大卫生观包括的主要内容A.卫生事业结构简单,是一种刚起步的社会性事业 B.生物
最新回复
(
0
)