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}.
publicclassTestFive{privateintx;publicvoidfoo(){intcurrent=x;x=current+1;}publicvoidgo(){for(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}.
相关考题:
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.
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.
publicabstractclassShape{privateintx;privateinty;publicabstractvoiddraw();publicvoidsetAnchor(intx,inty){this.x=x;this.y=y;}}WhichtwoclassesusetheShapeclasscorrectly?() A.publicclassCircleimplementsShape{privateintradius;}B.publicabstractclassCircleextendsShape{privateintradius;}C.publicclassCircleextendsShape{privateintradius;publicvoiddraw();}D.publicabstractclassCircleimplementsShape{privateintradius;publicvoiddraw();}E.publicclassCircleextendsShape{privateintradius;publicvoiddraw(){/*codehere*/}}F.publicabstractclassCircleimplementsShape{privateintradius;publicvoiddraw(){/codehere*/}}
A.f(-x,y)=f(x,y),f(x,-y)=-f(x,y)B.f(-x,y)=f(x,y),f(x,-y)=f(x,y)C.f(-x,y)=-f(x,y),f(x,-y)=-f(x,y)D.f(-x,y)=-f(x,y),f(x,-y)=f(x,y)
若f(-x)=f(x),且在(0,+∞)内f′(x)>0,f″(x)<0,则f(x)在(-∞,0)内( )。A.f′(x)<0,f″(x)<0B.f′(x)<0,f″(x)>0C.f′(x)>0,f″(x)<0D.f′(x)>0,f″(x)>0
若f(-x)=f(x),且在(0,+∞)内f′(x)>0,f″(x)<0,则f(x)在(-∞,0)内( )。《》( )A.f′(x)<0,f″(x)<0B.f′(x)<0,f″(x)>0C.f′(x)>0,f″(x)<0D.f′(x)>0,f″(x)>0
若f(x)=-f(-x),在(0,+∞)内f′(x)>0,f″(x)>0,则在(-∞,0)内( )《》( )A.f′(x)<f″(x)<0B.f′(x)<f″(x)>0C.f′(x)>f″(x)<0D.f′(x)>f″(x)>0
下列关于整除的命题中,正确的是______。A.若f(x)|g(x)+h(x),则f(x)|g(x)或f(x)|h(x)B.若f(x)|g(x)+h(x),且f(x)|g(x),则f(x)|h(x)C.若f(x)|g(x)h(x),则f(x)|g(x)或f(x)|h(x)D.若f(x)|g(x)h(x),且f(x)不整除g(x),则f(x)|h(x)