阅读下列说明和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 FootDecorator extends Decorator{ public FootDecorator(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 header 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) ticket.printInvoice() (3) ticket.printInvoice() (4) new FootDecorator(new HeadDecorator(t)) (5) new FootDecorator(new HeadDecorator(new Decorator(null)))
【解析】
试题分析
本题考查的是面向对象程序设计和设计模式。本题涉及的设计模式是装饰模式。装饰模式(Decorator) :动态地给一个对象添加一些额外的职责。它提供了用子类打展功能的一个灵活的替代,比派生一个子类更加灵活。
对于程序填空可以参照代码上下文、题干说明和设计模式综合考虑。
对于第(1) 空,是对printInvoice方法的具体调用,在Decorator是 装饰类,继承了Invoice发票类。此处需要填写的是printInvoice方法的方法体,根据Decorator类的上下文,已定义ticket对象,所以此处调用printinvoice方法的是ticket,第(1) 空填写ticket printlnvoice()。
对于第(2) (3) 空,根据类图可知,分别是HeadDecorator抬头 类、FootDecorator脚注类调用printInvoice方法的方法体,由于在这两个类中并没有定义属性,只有借助其超类的构造函数,所以这两个地方调用printlnvoice方法的是它们的超类,即(2) (3) 填写的是super.printInvoice()。
对于第(4) (5) 空,考查的是对装饰模式的调用,都是main函数中实例化的过程,根据输出结果可以看到,第(4)空实例化ticket对象,可以输出抬头、内容、脚注3个部分, 因此需要调用三者的printInvoice()方法, 前面已经实例化了一个Invoice对象t,可以利用给子类实例化,因此第(4) 空填写new HeadDecorator(new FootDecorator());而第(5)空没有输出具体内容,只有抬头和脚注部分,可以看到这里的Invoice对象应该是空,所以第(5) 空填写new HeadDecorator(new FootDecorator(nl)。
一台主机的IP地址为202.123.25.36,掩码为255.255.254.0。如果该主机需要在该网络进行直接广播,那么它应该使用的目的地址为( )
在计算机系统的日常维护工作中,应当注意硬盘工作时不能__(2)__。另外,需要防范病毒,而__(3)__是不会被病毒感觉的。
有 4 个 IP 地址:201.117.15.254、201.117.17.01、201.117.24.5 和 201.117.29.3,如果子网掩码为 255.255.248.0,则这 4 个地址分别属于3个子网;其中属于同一个子网的是()
在异步通信中,每个字符包含1位起始位、7位数据位、1位奇偶位和1位终止位,每秒钟传送200个字符,采用4相位调制,则码元速率为()。
在 Windows 中,运行( )命令得到下图所示结果。以下关于该结果的叙述中,错误的是( )。
Pinging 59.74.111.8 with 32 bytes of data:
Reply from 59.74.111.8: bytes=32 time=3ms TTL=60
Reply from 59.74.111.8: bytes=32 time=5ms TTL=60
Reply from 59.74.111.8: bytes=32 time=3ms TTL=60
Reply from 59.74.111.8: bytes=32 time=5ms TTL=60
Ping statistics for 59.74.111.8:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 3ms, Maximum = 5ms, Average = 4ms
在ISO OSF/RM参考模型中,七层协议中的__(1)__利用通信子网提供的服务实现两个用户进程之间端到端的通信。在这个模型中,如果A用户需要通过网络向B用户传送数据,则首先将数据送入应用层,在该层给它附加控制信息后送入表示层;在表示层对数据进行必要的变换并加头标后送入会话层;在会话层加头标送入传输层;在传输层将数据分解为__(本题)__后送至网络层;在网络层将数据封装成__(3)__后送至数据链路层;在数据链路层将数据加上头标和尾标封装成__(4)__后发送到物理层;在物理层数据以__(5)__形式发送到物理线路。B用户所在的系统接收到数据后,层层剥去控制信息,把原数据传送给B用户。
在OSI/RM中,解释应用数据语义的协议层是()。
在TCP/IP协议栈中,ARP协议的作用是(),RARP协议的作用是(请作答此空)。
在地址 http://www.dailynews.com.cn/channel/welcome.htm 中,www.dailynews.com.cn 表示( ),welcome.htm 表示(请作答此空)。
在电子表格软件Excel中,假设A1单元格的值为15,若在A2单元格输入“=AND(15<A1,A1<100)”,则A2单元格显示的值为 ()