题目内容 (请给出正确答案)
[主观题]

importjava.util.*;publicclassNameList{priv

importjava.util.*;

publicclassNameList{

privateListnames=newArrayList();

publicsynchronizedvoidadd(Stringname){names.add(name);}

publicsynchronizedvoidprintAll(){

for(inti=0;iSystem.out.print(names.get(i)+);

}

}

publicstaticvoidmain(String[]args){

finalNameListsl=newNameList();

for(inti=0;i<2;i++){

newThread(){

publicvoidruin(){

sl.add(”A”);

sl.add(”B”);

sl.add(”C”);

sl.printAll();

}

}.start();

}

}

}

Whichtwostatementsaretrueifthisclassiscompiledandrun?()

查看答案
如搜索结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能会需要:
您的账号:
发送账号密码至手机
发送
更多“importjava.util.*;publicclassN…”相关的问题

第1题

publicclassTestFive{privateintx;publicvoidfoo(){intcurrent=x;x=current+1;}publicvoidgo(){f

or(inti=0;i<5;i++){newThread(){publicvoidrun(){foo();System.out.print(x+,);}}.start();}}}Whichtwochanges,takentogether,wouldguaranteetheoutput:1,2,3,4,5,?()

A.Movetheline12printstatementintothefoo()method.

B.Changeline7topublicsynchronizedvoidgo(){.

C.Changethevariabledeclarationonline3toprivatevolatileintx;.

D.Wrapthecodeinsidethefoo()methodwithasynchronized(this)block.

E.Wraptheforloopcodeinsidethego()methodwithasynchronizedblocksynchronized(this){//forloopcodehere}.

点击查看答案

第2题

Whichthreewillcompileandrimwithoutexception?()

A.privatesynchronizedObjecto;

B.voidgo(){synchronized(){/*codehere*/}}

C.publicsynchronizedvoidgo(){/*codehere*/}

D.privatesynchronized(this)voidgo(){/*codehere*/}

E.voidgo(){synchronized(Object.class){/*codehere*/}}

F.voidgo(){Objecto=newObject();synchronized(o){/*codehere*/}}

点击查看答案

第3题

publicclassTestSevenextendsThread{privatestaticintx;publicsynchronizedvoiddoThings(){intcurrent=x;current++;x=current;}publicvoidrun(){doThings();}}Whichistrue?()

A.Compilationfails.

B.Anexceptionisthrownatruntime.

C.Synchronizingtherun()methodwouldmaketheclassthread-safe.

D.Thedatainvariable“x”areprotectedfromconcurrentaccessproblems.

E.DeclaringthedoThings()methodasstaticwouldmaketheclassthread-safe.

F.WrappingthestatementswithindoThings()inasynchronized(newObject()){}blockwouldmaketheclassthread-safe.

点击查看答案

第4题

publicclassTransfers{publicstaticvoidmain(

publicclassTransfers{

publicstaticvoidmain(String[]args)throwsException{

Recordr1=newRecord();

Recordr2=newRecord();

doTransfer(r1,r2,5);

doTransfer(r2,r1,2);

doTransfer(r1,r2,1);

//printtheresult

System.out.println(”rl=+r1.get()+,r2=”+r2.get());

}

privatestaticvoiddoTransfer(

finalRecorda,finalRecordb,finalintamount){

Threadt=newThread(){

publicvoidrun(){

newClerk().transfer(a,b,amount);

}

};

t.start();

}

}

classClerk{

publicsynchronizedvoidtransfer(Recorda,Recordb,intamount){

synchronized(a){

synchronized(b){

a.add(-amount);

b.add(amount);

}

}

}

}

classRecord{

intnum=10;

publicintget(){returnnum;}

publicvoidadd(intn){num=num+n;}

}

IfTransfers.main()isrun,whichthreearetrue?()

点击查看答案

第5题

classComputationextendsThread{privateintnu

classComputationextendsThread{

privateintnum;

privatebooleanisComplete;

privateintresult;

publicComputation(intnum){this.num=num;}

publicsynchronizedvoidrun(){

result=num*2;

isComplete=true;

notify();

}

publicsynchronizedintgetResult(){

while(!isComplete){

try{

wait();

}catch(InterruptedExceptione){}

}

returnresult;

}

publicstaticvoidmain(String[]args){

Computation[]computations=newComputation[4];

for(inti=0;i<computations.length;i++){

computations[i]=newComputation(i);

computations[i].start();

}

for(Computationc:computations)

System.out.print(c.getResult()+);

}

}

Whatistheresult?()

点击查看答案

第6题

voidwaitForSignal(){Objectobj=newObject();synchronized(Thread.currentThread()){obj.wait();obj.notify();}}Whichistrue?()

A.ThiscodemaythrowanInterruptedException.

B.ThiscodemaythrowanIllegalStateException.

C.ThiscodemaythrowaTimeoutExceptionaftertenminutes.

D.Thiscodewillnotcompileunless“obj.wait()”isreplacedwith“((Thread)obj).wait()”.

E.Reversingtheorderofobj.wait()andobj.notify()maycausethismethodtocompletenormally.

F.Acalltonotify()ornotifyAll()fromanotherthreadmaycausethismethodtocompletenormally.

点击查看答案

第7题

fooandbararepublicreferencesavailabletomanyotherthreads.fooreferstoaThreadandbarisanObject

.Thethreadfooiscurrentlyexecutingbar.wait().Fromanotherthread,whichstatementisthemostreliablewaytoensuethatfoowillstopexecutingwait()?

A.foo.notify();

B.bar.notify();

C.foo.notifyAll();

D.Thread.notify();

E.bar.notiFYAll();

F.Object.notify();

点击查看答案

第8题

packagetest;classTarget{publicStringname=hello”;}Whatcandirectlyaccessandchangethevalueofthevariablename?()

A.anyclass

B.onlytheTargetclass

C.anyclassinthetestpackage

D.anyclassthatextendsTarget

点击查看答案

第9题

publicclassTarget{2.privateinti=0;3.publicintaddOne(){4.return++i;5.}6.}And:1.publicclas

1.publicclassTarget{2.privateinti=0;3.publicintaddOne(){4.return++i;5.}6.}And:1.publicclassClient{2.publicstaticvoidmain(String[]args){3.System.out.println(newTarget().addOne());4.}5.}WhichchangecanyoumaketoTargetwithoutaffectingClient?()

A.Line4ofclassTargetcanbechangedtoreturni++;

B.Line2ofclassTargetcanbechangedtoprivateinti=1;

C.Line3ofclassTargetcanbechangedtoprivateintaddOne(){

D.Line2ofclassTargetcanbechangedtoprivateIntegeri=0;

点击查看答案

第10题

packagegeometry;publicclassHypotenuse{publicInnerTriangleit=newInnerTriangle();classInnerTriangle{publicintbase;publicintheight;}}Whichistrueabouttheclassofanobjectthatcanreferencethevariablebase?()

A.Itcanbeanyclass.

B.Noclasshasaccesstobase.

C.Theclassmustbelongtothegeometrypackage.

D.TheclassmustbeasubclassoftheclassHypotenuse.

点击查看答案
热门考试 全部 >
相关试卷 全部 >
账号:
你好,尊敬的上学吧用户
发送账号至手机
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改
谢谢您的反馈

您认为本题答案有误,我们将认真、仔细核查,
如果您知道正确答案,欢迎您来纠错

警告:系统检测到您的账号存在安全风险

为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!

微信搜一搜
上学吧
点击打开微信
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反上学吧购买须知被冻结。您可在“上学吧”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
微信搜一搜
上学吧
点击打开微信