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.
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.
相关考题:
●试题三阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】设有一个带表头结点的双向循环链表L,每个结点有4个数据成员:指向前驱结点的指针prior、指向后继结点的指针next、存放数据的成员data和访问频度freq。所有结点的freq初始时都为0。每当在链表上进行一次L.Locate(x)操作时,令元素值x的结点的访问频度freq加1,并将该结点前移,链接到现它的访问频度相等的结点后面,使得链表中所有结点保持按访问频度递减的顺序排列,以使频繁访问的结点总是靠近表头。【函数】void Locate(int &x){结点类型说明*p=first-next;while(p!=frist && (1) )P=P-next;if (p!=first)/*链表中存在x*/{ (2) ;结点类型说明*current=p;/*从链表中摘下这个结点*/Current-prior-next=current-next;Current-next-prior=current-prior;P=current-prior;/*寻找重新插入的位置*/While(p!=first && (3) )p=p-prior;Current-next= (4) ;/*插入在P之后*?Current-prior=P;P-next-prior=current;P-next= (5) ;}else printf("Sorry.Not find!\n");/*没找到*/}
请阅读下面的程序,选择正确的运行结果()。classDemo/{privatestaticintx;publicstaticvoidmain(String[]args)/{System.out.println(x++);/}/} A.无结果B.0C.1D.编译失败
publicclassTestFive{privateintx;publicvoidfoo(){intcurrent=x;x=current+1;}publicvoidgo(){for(inti=0;i5;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}.
publicclassThreads1{intx=0;publicclassRunnerimplementsRunnable{publicvoidrun(){intcurrent=0;for(int=i=0;i4;i++){current=x;System.out.print(current+,);x=current+2;}}}publicstaticvoidmain(String[]args){newThreads1().go();}publicvoidgo(){Runnabler1=newRunner();newThread(r1).start();newThread(r1).start();}}Whichtwoarepossibleresults?()A.0,2,4,4,6,8,10,6,B.0,2,4,6,8,10,2,4,C.0,2,4,6,8,10,12,14,D.0,0,2,2,4,4,6,6,8,8,10,10,12,12,14,14,E.0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14,
publicclassStarterextendsThread{privateintx=2;publicstaticvoidmain(String[]args)throwsException{newStarter().makeItSo();}publicStarter(){x=5;start();}publicvoidmakeItSo()throwsException{join();x=x-1;System.out.println(x);}publicvoidrun(){x*=2;}}Whatistheoutputifthemain()methodisrum?()A.4B.5C.8D.9E.Compilationfails.F.Anexceptionisthrownatruntime.G.Itisimpossibletodetermineforcertain.
Whichlinecontainsaconstructorinthisclassdefinition?()publicclassCounter{//(1)intcurrent,step;publicCounter(intstartValue,intstepValue){//(2)set(startValue);setStepValue(stepValue);}publicintget(){returncurrent;}//(3)publicvoidset(intvalue){current=value;}//(4)publicvoidsetStepValue(intstepValue){step=stepValue;}//(5)}A.Codemarkedwith(1)isaconstructorB.Codemarkedwith(2)isaconstructorC.Codemarkedwith(3)isaconstructorD.Codemarkedwith(4)isaconstructorE.Codemarkedwith(5)isaConstructor
1、请阅读下面的程序,选择正确的运行结果。() class Demo{ private static int x ; public static void main(String[] args){ System.out.println(x++); } }A.0B.1C.无结果D.编译失败
请阅读下面的程序,选择正确的运行结果。 class Demo{ private static int x ; public static void main(String[] args){ System.out.println(x++); } }A.0B.1C.无结果D.编译失败
请阅读下面的程序,选择正确的运行结果。() class Demo{ private static int x ; public static void main(String[] args){ System.out.println(x++); } }A.0B.1C.无结果D.编译失败