publicclassTestSevenextendsThread{privatestaticintx;publicsynchronizedvoiddoThings(){intcurrent=x;current++;x=current;}publicvoidrun(){doThings();}}Whichistrue?()A.Compilationfails.B.Anexceptionisthrownatruntime.C.Synchronizingtherun()methodwouldmakethecl

题目
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?() ”相关问题
  • 第1题:

    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.4

    B.5

    C.8

    D.9

    E.Compilationfails.

    F.Anexceptionisthrownatruntime.

    G.Itisimpossibletodetermineforcertain.


    参考答案:D

  • 第2题:

    1、请阅读下面的程序,选择正确的运行结果。() class Demo{ private static int x ; public static void main(String[] args){ System.out.println(x++); } }

    A.0

    B.1

    C.无结果

    D.编译失败


    A

  • 第3题:

    请阅读下面的程序,选择正确的运行结果。() class Demo{ private static int x ; public static void main(String[] args){ System.out.println(x++); } }

    A.0

    B.1

    C.无结果

    D.编译失败


    A

  • 第4题:

    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)isaconstructor

    B.Codemarkedwith(2)isaconstructor

    C.Codemarkedwith(3)isaconstructor

    D.Codemarkedwith(4)isaconstructor

    E.Codemarkedwith(5)isaConstructor


    参考答案:B

  • 第5题:

    请阅读下面的程序,选择正确的运行结果。 class Demo{ private static int x ; public static void main(String[] args){ System.out.println(x++); } }

    A.0

    B.1

    C.无结果

    D.编译失败


    ass Demo{private static int x ;public static void main(String[] args){System.out.println(x++);}}