首页 > 计算机等级考试
题目内容 (请给出正确答案)
[主观题]

阅读下面实现堆栈类并发控制的部分代码public class DataStack } private int idx=0; private in

阅读下面实现堆栈类并发控制的部分代码 public class DataStack } private int idx=0; private int[] data=new int[8]; public void push(int i) { ______ { data[idx]=I: idx++; } } … } 程序中下画线处应填入的正确选项是

A.synchronized

B.synchronized(this)

C.synchronized()

D.synchronized(idx)

查看答案
答案
收藏
如果结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能还需要:
您的账号:
发送账号密码至手机
发送
安装优题宝APP,拍照搜题省时又省心!
更多“阅读下面实现堆栈类并发控制的部分代码public class…”相关的问题
第1题
阅读下面实现堆栈类并发控制的部分代码 public class DataStack{ private int idx=0; private in
t[]data=new int[8]; public void push(int i){ . ________________{ data[idx]=i; idx + +; } } } …… } 在程序下画线处填入正确选项是

A.synchronized

B.synchronized(this)

C.synchronized()

D.synchronized(idx)

点击查看答案
第2题
阅读下列一个支持多线程并发操作的堆栈类代码段public class MyStack{private int idx=0;private

阅读下列一个支持多线程并发操作的堆栈类代码段 public class MyStack{ private int idx=0; private int[]data=new int[8]; public______void push(int i){ data[idx]=i; idx + +; } …… } 在下画线处应填入的是

A.synchronized

B.wait

C.blocked

D.interrupt

点击查看答案
第3题
阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某灯具厂商欲生产一个

阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。

【说明】

某灯具厂商欲生产一个灯具遥控器,该遥控器具有7个可编程的插槽,每个插槽都

有开关按钮,对应着一个不同的灯。利用该遥控器能够统一控制房间中该厂商所有品牌

灯具的开关,现采用Command(命令)模式实现该遥控器的软件部分。command模式

的类图如图6-1所示。

阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某灯具厂商欲生产一个

【Java代码】

阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某灯具厂商欲生产一个

阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某灯具厂商欲生产一个

}

点击查看答案
第4题
阅读以下应用说明、图和Java代码,根据要求回答问题1至问题5。 【说明】 Stack类是java. ntil包中专门

阅读以下应用说明、图和Java代码,根据要求回答问题1至问题5。

【说明】

Stack类是java. ntil包中专门用来实现栈的工具类。以下Java程序是一个不使用库函数而实现字符串反转的程序。例如,输入:123456,则输出:654321:输入:asdfeg,则输出:gefdsa。

【Java程序】

import java.applet.Applet;

import java.awt.*;

import java.awt.event.*;

import java.util.*;

public class UseStack extends Applet implements ActionListener

{ Stack MyStack;

Label prompt=new Label("输入要反转字符:");

Button pushBtn=new Button("压栈");

Button popBtn=new Button("弹栈"); //反转

TextField input=new TextField(5);

int[] DrawStack =new int[10]; //记录堆栈中数据

int[] PoppedOut=new int[20]; //记录被弹出的数据

int StackCnt=0; //记录模拟堆栈的数组中的数据个数

String msg=" ";

public void init()

{ MyStack=new Stack();

add(prompt);

add(input);

add(pushBtn);

add(popBtn);

pushBtn.addActionListener(this);

(1)

}

public void paint(Graphics g)

{ for (int i=10; i<StackCnt; i++) //模拟显示堆栈内部的数据排列情况

{ g.drawRect(50,200-i*20,80,20);

g.drawString(Integer.toString(DrawStack[i]),80,215-i*20);

}

for (int i=0;(2) ) //显示被弹出的数据

g.drawString(Integer.toString(PoppedOut[i]),200+i*20,100);

g.drawString("堆栈",70,236);

g.drawString("栈底",135,225);

g.drawString("栈顶",160,225-StackCnt*20);

g.drawString(msg,200,140);

}

public void actionPerformed((3) )

{ if (e.getAct ionCommand () == "压栈") //压栈操作

{ if(StackCnt<10)

{ MyStack.push(new Integer((4) ));

DrawStack[StackCnt++]=Integer.parseInt(input.getText() );

input.setText (" ");

}

else

msg="输入数据过多,请先弹栈!"

}

else if (e.getActionCommand () == "弹栈") //弹栈操作

{ if((5) )

{ StackCnt--;

PoppedOut[PopCnt++]=[(Integer)(MyStack.pop())).intValue();

}

else

msg="堆栈已空,不能再弹栈!";

}

repaint();

}

}

点击查看答案
第5题
阅读以下关于某绘图系统的技术说明、部分UML类图及Visual Basic程序,将Visual Basic程序中(1)~(6)

阅读以下关于某绘图系统的技术说明、部分UML类图及Visual Basic程序,将Visual Basic程序中(1)~(6)空缺处的语句填写完整。

【说明】

某绘图系统定义了一个抽象类Ishape,现有3个类Cpoint,CLine和Ccircle,它们都具有IShape界面。相应的类图关系如图5-11所示。

阅读以下关于某绘图系统的技术说明、部分UML类图及Visual Basic程序,将Visual Ba

已知某第三方库已经提供了XCircle类,且完全满足CCircle图元显示时所需的功能。【Visual Basic代码6-1】是抽象类IShape类模块内容。【Visual Basic代码6-2】实现了类CCircle的IShape界面,并使用了XCircle提供的显示功能。

XCircle提供的显示功能方法接口为displayIt。

【Visual Basic代码6-1】

Publie Color As Long

Sub draw()

'方法体不包括可执行语句

End Sub

Sub move(stepx As Single, stepy As Single)

'方法体不包括可执行语句

End Sub

【Visual Basic代码6-2】

(1)

Private color As Long

… '其他定义省略

Private ridged As (2)

Private Sub Class_Initialize()

Set bridged=(3)

End Sub

Private Property (4) ()As Long

IShape_Color=color

End Property

Private Property (5) (ByVal newColor As Long)

Color=newColor

End Property

Private Sub IShape_draw() 使用XCircle提供的显示功能

(6)

End Sub

Private Sub IShape_move(stepx As Single, stepy As Single)

… '省略描述

End Sub

点击查看答案
第6题
试题五(共15分)阅读下列说明和C++-代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明】某发

试题五(共15分)

阅读下列说明和C++-代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

【说明】

某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。

试题五(共15分)阅读下列说明和C++-代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明

【C++代码】

include <iostream>

using namespace std;

class invoice{

public:

(1) {

cout《 "This is the content of the invoice!"《 endl;

}

};

class Decorator : public invoice {

Invoice *ticket;

public:

Decorator(lnvoice *t) { ticket = t; }

void printinvoice(){

if(ticket != NULL)

(2);

}

};

class HeadDecorator : public Decorator{

public:

HeadDecorator(lnvoice*t): Decorator(t) { }

void printinvoice0 {

cout《 "This is the header of the invoice! "<< endl;

(3) ;

}

};

class FootDecorator : public Decorator{

public:

FootDecorator(invoice *t): Decorator(t) { }

void printlnvoice() {

(4) ;

cout《 "This is the footnote of the invoice!"《 endl;

}

};

int main(void) {

Invoice t;

FootDecorator f(&t);

HeadDecorator h(&f);

H.printlnvoice();

cout< < “_____”< < endl;

FootDecorator a(NULL);

HeadDecorator b((5) );

B.printinvoice();

return 0;

}

程序的输出结果为:

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!

点击查看答案
第7题
试题六(共15分) 阅读以下说明和Java代码,填补Java代码中的空缺(1)~(5),将解答写在答题纸的对应栏

试题六(共15分)

阅读以下说明和Java代码,填补Java代码中的空缺(1)~(5),将解答写在答题纸的对应栏内。

【说明】

已知某公司主要有两大类耗电资产(Asset):计算机(ComputerAsset)和建筑物(Building Asset)。为了节约能源,通过控制各种电源,将可关闭的房灯、计算机显示器等在夜间关闭。

为了实现上述需求,设计了如图6-1所示的类图,并用下面的Java代码加以实现。

试题六(共15分) 阅读以下说明和Java代码,填补Java代码中的空缺(1)~(5),将解答写在答

【Java代码】

abstract class Asset{ /*通用资产,基类*/}

interface PowerSwitchable{ /*可在夜间关闭电源的物体实现该接口*/

public void powerDown();

public void powerUp();

}

abstract class BuildingAsset extends Asset{/*建筑物资产*/

protected int room;

public BuildingAsset(int room){ this.room= room; }

}

abstract class BuildingLight extends BuildingAsset{

//灯的通用信息:flourescent/incandescent等,略

BuildingLight(int roomNumber){ super(roomNumber);}

}

classEmergencyLight (1) {/*应急灯,永不关闭*/

EmergencyLight(int roomNumber){

super(roomNumber);

}

}

class RoomLights (2) {

RoomLights(int roomNumber){ super(roomNumber); }

public void powerDown(){ /*关电源,代码略*/}

public void powerUp(){/*开电源,代码略*/}

}

/*ComputerAsset、 Computer CPU和Computer Monitor代码略*/

public class BuildingManagement{

Asset things[]= new Asset[24];

int numltems=0;

public void goodNight(){/*值班员定时“关闭”时调用,关闭可关闭的电源*/

for (int i=0; i<things.length; i++)

if(things[i] instanceof (3) )

((PowerSwitchable)things[i]).powerDown();

}

/*goodMorning()与goodNight()类似,依次调用powerUp(),其实现细节此处略*/

public void add(Asset thing){ /*为建筑添加资产*/

things[ (4) ]=thing;

}

public static void main(String[] args){

BuildingManagementbl= (5) BuildingManagement();

bl.add(new RoomLights(101)); //101房间的控制灯

bl.add(new EmergencyLight(101)); //101房间的应急灯

bl.add(new ComputerCPU(10104));//101房间4号桌上的计算机主机

bl.add(new ComputerMonitor(10104)); // 101房间4号桌上的计算机显示器

bl.goodNight();

}

}

点击查看答案
第8题
阅读下面代码class Test implements Runnable { public int run() { int i=0; while(true) {

阅读下面代码 class Test implements Runnable { public int run() { int i=0; while(true) { i++; System.out.println("i="+i); } } } 上述代码的编译结果是

A.程序通过编译,并且run()方法可以正常输出递增的i值

B.程序通过编译,调用run()方法将不显示任何输出

C.程序不能通过编译,因为while的循环控制条件不能为true

D.程序不能通过编译,因为run()方法的返回值类型不是void

点击查看答案
第9题
缓冲区溢出攻击是针对程序空间的哪些部分进行溢出?()

A.代码段

B.堆

C.数据段

D.堆栈段

点击查看答案
退出 登录/注册
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改