publicclassThreads1{intx=0;publicclassRunnerimplementsRunnable{publicvoidrun(){intcurrent=0;for(int=i=0;i<4;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,
第1题:
要定义整型数组x,使之包括初值为0的三个元素,下列语句中错误的是()
A.int x[3]={0,0,0};
B.int x[ ]={0};
C.int x[3]={0};
D.int x[ ]={0,0,0};
第2题:
要定义整型数组x,使之包括初值为0的三个元素,下列语句中错误的是()
A.int x[ ]={0,0,0};
B.int x[ ]={0};
C.int x[3]={0};
D.int x[3]={0,0,0};
第3题:
1、要定义整型数组x,使之包括初值为0的三个元素,下列语句中错误的是()
A.int x[3]={0,0,0};
B.int x[ ]={0};
C.int x[3]={0};
D.int x[ ]={0,0,0};
第4题:
下列函数原型声明中错误的是
A.void Fun(int x=0,int y=0);
B.void Fun(int x,int y);
C.void Fun(int x,int y=0);
D.void Fun(int x=0,int y);
第5题:
下列函数原型声明中错误的是( )。
A.void Fun(int x=0,int y=0);
B.void Fun(int x,int y);
C.void Fun(int x,int y=0);
D.void Fun(int x=0,int y);
第6题:
下列函数原型声明中错误的是( )。
A.void fuc(int x=0,int y=0)
B.void fnc(int x,int y)
C.void fuc(int x,int y=0)
D.void fuc(int x=0,int y)
第7题:
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}.
第8题:
A.Compilationfails.
B.Anexceptionisthrownatruntime.
C.Synchronizingtherun()methodwouldmaketheclassthread-safe.
D.Thedatainvariable“x”areprotectedfromconcurrentaccessproblems.
E.DeclaringthedoThings()methodasstaticwouldmaketheclassthread-safe.
F.WrappingthestatementswithindoThings()inasynchronized(newObject()){}blockwouldmaketheclassthread-safe.
第9题:
下列函数原型声明中错误的是
A.void Fun(int x=O,int y=0);
B.void Fun(int x,int y);
C.void Fun(int x,int y=0);
D.void Fun(int x=0,int y);