A.Compilationfails.
B.Anexceptionisthrownatruntime.
C.Synchronizingtherun()methodwouldmaketheclassthread-safe.
D.Thedatainvariable“x”areprotectedfromconcurrentaccessproblems.
E.DeclaringthedoThings()methodasstaticwouldmaketheclassthread-safe.
F.WrappingthestatementswithindoThings()inasynchronized(newObject()){}blockwouldmaketheclassthread-safe.
第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.
第2题:
1、请阅读下面的程序,选择正确的运行结果。() class Demo{ private static int x ; public static void main(String[] args){ System.out.println(x++); } }
A.0
B.1
C.无结果
D.编译失败
第3题:
请阅读下面的程序,选择正确的运行结果。() class Demo{ private static int x ; public static void main(String[] args){ System.out.println(x++); } }
A.0
B.1
C.无结果
D.编译失败
第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
第5题:
请阅读下面的程序,选择正确的运行结果。 class Demo{ private static int x ; public static void main(String[] args){ System.out.println(x++); } }
A.0
B.1
C.无结果
D.编译失败